Class JfrLogOutput
- All Implemented Interfaces:
LogLifecycle, LogOutput, LogOutput.ProvidesEncoder, Flushable, AutoCloseable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface LogOutput
LogOutput.AbstractOutputStreamOutput, LogOutput.ContentType, LogOutput.OutputProvider, LogOutput.OutputType, LogOutput.ProvidesEncoder, LogOutput.ThreadSafeLogOutput, LogOutput.WriteMethodModifier and TypeInterfaceDescriptionstatic classAbstract output on output stream.static interfaceThe content type of the binary data passed to the output from an encoder.static interfaceFinds output based on URI.static enumOutput type useful for defaults and categorization.static interfaceMarks an output that supplies its ownLogEncoderinstead of relying entirely onLogAppender.APPENDER_ENCODER_PROPERTYorLogEncoderRegistry.encoderForOutputType(OutputType).static interfaceMarker interface that the output is thread safe.static enumThe preferred write style of an output.Nested classes/interfaces inherited from interface LogOutput.ProvidesEncoder
LogOutput.ProvidesEncoder.PolicyModifier and TypeInterfaceDescriptionstatic enumWhether aLogOutput.ProvidesEncoder'sLogOutput.ProvidesEncoder.encoder(String, LogConfig)can be overridden by another, explicitly configured encoder. -
Field Summary
FieldsFields inherited from interface LogOutput
FILE_SCHEME, STDERR_SCHEME, STDERR_URI, STDOUT_SCHEME, STDOUT_URIModifier and TypeFieldDescriptionstatic final StringFile URI scheme.static final StringFileDescriptor.errURI scheme.static final URIStandard ERR URIstatic final StringFileDescriptor.outURI scheme.static final URIStandard OUT URI. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a JFR output that emits events only for whatever externally started Flight Recorder session (if any) is currently running, without managing a recording of its own.JfrLogOutput(URI uri, @Nullable Path destination) Creates a JFR output. -
Method Summary
Modifier and TypeMethodDescriptionHints to the buffer like what write style of the output and maximum buffer size.voidclose()Will close the output and should only be called by the owning appender.The encoder this output supplies, given the samename/configthe output itself was provided with.voidflush()Flushes if the output is maintaining a buffer.voidStarts a component.type()Gross categorization of an output.uri()The uri of the output.voidwrite(LogEvent event, byte[] bytes, int off, int len, LogOutput.ContentType contentType) Analogous toOutputStream.write(byte[], int, int).voidWrites a string and by default with charsetStandardCharsets.UTF_8.Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface LogOutput
reopen, write, write, write, write, writeModifier and TypeMethodDescriptiondefault voidreopen()Attempts to reopen the output if supported and SHOULD only be called by the appender!default voidwrite(LogEvent[] events, int count, LogEncoder encoder) Write a batch of events by default callsLogOutput.write(LogEvent[], int, LogEncoder, Buffer).default voidwrite(LogEvent[] events, int count, LogEncoder encoder, LogEncoder.Buffer buffer) Write a batch of events reusing the provided buffer and by default callingLogOutput.write(LogEvent, Buffer)for each event synchronously.default voidwrite(LogEvent event, byte[] bytes, LogOutput.ContentType contentType) Analogous toOutputStream.write(byte[]).default voidwrite(LogEvent event, LogEncoder.Buffer buffer) Writes a prepared buffer and by default drains the buffer to this output.default voidwrite(LogEvent event, ByteBuffer buf, LogOutput.ContentType contentType) Write event with byte buffer.Methods inherited from interface LogOutput.ProvidesEncoder
policyModifier and TypeMethodDescriptiondefault LogOutput.ProvidesEncoder.Policypolicy()WhetherLogOutput.ProvidesEncoder.encoder(String, LogConfig)can be overridden by an explicitly configured encoder.
-
Field Details
-
JFR_SCHEME
-
-
Constructor Details
-
JfrLogOutput
public JfrLogOutput()Creates a JFR output that emits events only for whatever externally started Flight Recorder session (if any) is currently running, without managing a recording of its own. -
JfrLogOutput
Creates a JFR output.- Parameters:
uri- the output's own configured URI, returned as-is byuri().destination- if not null, a file this output starts and owns its ownRecordingagainst for as long as the output is open (seestart(LogConfig),close()); if null, events are only captured by whatever externally started recording (if any) is already running.
-
-
Method Details
-
uri
-
start
Description copied from interface:LogLifecycleStarts a component.- Specified by:
startin interfaceLogLifecycle- Specified by:
startin interfaceLogOutput- Parameters:
config- log config.
-
type
Description copied from interface:LogOutputGross categorization of an output. -
bufferHints
Description copied from interface:LogOutputHints to the buffer like what write style of the output and maximum buffer size. The output should still honor all write methods but this signals to the encoder which style it prefers.- Specified by:
bufferHintsin interfaceLogOutput- Returns:
- write mode.
-
encoder
Description copied from interface:LogOutput.ProvidesEncoderThe encoder this output supplies, given the samename/configthe output itself was provided with.- Specified by:
encoderin interfaceLogOutput.ProvidesEncoder- Parameters:
name- appender name.config- config.- Returns:
- encoder, see
LogOutput.ProvidesEncoder.policy()for whether it can be overridden.
-
write
-
write
public void write(LogEvent event, byte[] bytes, int off, int len, LogOutput.ContentType contentType) Description copied from interface:LogOutputAnalogous toOutputStream.write(byte[], int, int). -
flush
Description copied from interface:LogOutputFlushes if the output is maintaining a buffer. By default an appender will call this after each event in synchronous mode or after a batched group of events if in asynchronous mode unlessLogAppender.AppenderFlag.DISABLE_IMMEDIATE_FLUSHis set. -
close
Description copied from interface:LogOutputWill close the output and should only be called by the owning appender.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceLogLifecycle- Specified by:
closein interfaceLogOutput
-