Class JsonInvocationEventEmitter
- All Implemented Interfaces:
InvocationEventEmitter
InvocationEventEmitter that writes each event as a single line of
structured JSON through SLF4J, instead of the human-readable line produced
by Slf4jInvocationEventEmitter.
This exists for applications that ship their logs to a structured
backend (Loki, Elasticsearch, Datadog, and similar) that parses each log
line as JSON. Emitting Slf4jInvocationEventEmitter's prose line
into such a backend either fails to parse or gets indexed as one opaque
string field, losing the ability to filter or aggregate on individual
fields (for example querying every failed call for a given
className). This emitter writes every MethodInvocationEvent
field as its own JSON property instead, so the backend's own JSON parser
indexes them directly.
No JSON library is used or required: every field on
MethodInvocationEvent is a primitive, a String, or an
Instant, so a small hand-written writer is enough and
keeps this class dependency-free, consistent with the rest of this
library. String fields are escaped for quotes, backslashes, and control
characters before being written, since className, exception type
names, and caller identity ultimately originate from application code or
an authenticated principal, not arbitrary user input — but escaping them
anyway costs nothing and guarantees the emitted line is always valid JSON.
As with Slf4jInvocationEventEmitter, successful calls are
logged at INFO and failed calls at WARN, and the
exception message is never included, only its simple class name.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidemit(MethodInvocationEvent event) Publishes the given invocation event to whatever sink this implementation targets.
-
Constructor Details
-
JsonInvocationEventEmitter
public JsonInvocationEventEmitter()
-
-
Method Details
-
emit
Description copied from interface:InvocationEventEmitterPublishes 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:
emitin interfaceInvocationEventEmitter- Parameters:
event- the invocation event to publish, nevernull
-