Class JfrLogOutput

java.lang.Object
io.jstach.rainbowgum.jfr.JfrLogOutput
All Implemented Interfaces:
LogLifecycle, LogOutput, LogOutput.ProvidesEncoder, Flushable, AutoCloseable

public final class JfrLogOutput extends Object implements LogOutput, LogOutput.ProvidesEncoder
A LogOutput that commits each log event as a JFR event (see RainbowGumLogEvent) instead of writing anywhere.

The output prefers LogOutput.WriteMethod.STRING, so formatter-backed encoders hand the formatted message directly to write(LogEvent, String) without first turning it into bytes:

logging.appender.myappender.output=jfr:///
Per-event-type enablement, thresholds, and stack trace capture are controlled the same way as any other JFR event, e.g. with -XX:StartFlightRecording or a .jfc settings file - not through Rainbow Gum properties. If a Flight Recorder session that enables the relevant event type is not running, write(LogEvent, String) does (cheaply) nothing.

If the configured URI has a real path (anything past the root /), this output instead starts and owns its own Recording writing directly to that file for as long as the output is open, with every event type unconditionally enabled:

logging.appender.myappender.output=jfr:///var/log/myapp.jfr
In this mode JFR's own per-event enablement/threshold filtering is bypassed entirely - whether an event is captured is decided solely by Rainbow Gum's normal level resolver (the same one that already decides whether write(LogEvent, String) is called at all), not by JFR settings.

This output also implements LogOutput.ProvidesEncoder, supplying (as an overridable default, see LogOutput.ProvidesEncoder.Policy.DEFAULT) an encoder that renders the message followed by any key values, e.g. some message - {key=value} - no timestamp/level/logger prefix, since the JFR event already carries those as separate fields - so leaving encoder unset when output=jfr:/// picks this up automatically instead of the default TTLL encoder formatting a whole line only to throw most of it away.