Class Slf4jInvocationEventEmitter

java.lang.Object
com.fayupable.logged.spring.emitter.Slf4jInvocationEventEmitter
All Implemented Interfaces:
InvocationEventEmitter

public class Slf4jInvocationEventEmitter extends Object implements InvocationEventEmitter
Default InvocationEventEmitter that writes each event as a single, human-readable line through SLF4J.

Successful calls are logged at INFO, failed calls at WARN, since a failure surfacing through a @Logged method is operationally significant even though the exception itself already propagates to the caller. The exception message is never included, only its simple class name, consistent with MethodInvocationEvent.

The trace id and depth carried by the event are only appended to the log line when MethodInvocationEvent.depth() is greater than zero, that is, when the call is part of a chain of nested @Logged invocations. Root-level, non-nested calls are logged without this extra detail, keeping the common case concise.

MethodInvocationEvent.rootCauseType() is only appended to a failure line when it differs from MethodInvocationEvent.exceptionType(), that is, when the thrown exception actually wraps a different underlying cause. When the two are equal, showing the root cause a second time would add nothing, so it is omitted to keep the common case concise.

MethodInvocationEvent.callerIp() is only appended when present, that is, only for the security-sensitive methods explicitly annotated with @Logged(includeIp = true). It is deliberately shown alongside MethodInvocationEvent.callerIdentity() rather than only in its place, since the two answer different questions ("who" versus "from where") that both matter for the operations this attribute is meant for.

  • Constructor Details

    • Slf4jInvocationEventEmitter

      public Slf4jInvocationEventEmitter()
  • Method Details

    • emit

      public void emit(MethodInvocationEvent event)
      Description copied from interface: InvocationEventEmitter
      Publishes the given invocation event to whatever sink this implementation targets.

      Implementations must not throw checked or unchecked exceptions that would propagate back into the intercepted method call. Emission failures (for example a logging backend being unavailable) should be handled internally by the implementation.

      Specified by:
      emit in interface InvocationEventEmitter
      Parameters:
      event - the invocation event to publish, never null