Interface LogData
-
- All Known Implementing Classes:
LogContext
public interface LogDataA backend API for determining metadata associated with a log statement.Some metadata is expected to be available for all log statements (such as the log level or a timestamp) whereas other data is optional (class/method name for example). As well providing the common logging metadata, customized loggers can choose to add arbitrary key/value pairs to the log data. It is up to each logging backend implementation to decide how it interprets this data using the hierarchical key. See
Metadata.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description Object[]getArguments()Returns the arguments to be formatted with the message.LevelgetLevel()Returns the log level for the current log statement.ObjectgetLiteralArgument()Returns the single argument to be logged directly when no arguments were provided.StringgetLoggerName()Returns the logger name (which is usually a canonicalized class name) ornullif not given.LogSitegetLogSite()Returns the log site data for the current log statement.MetadatagetMetadata()Returns any additional metadata for this log statement.TemplateContextgetTemplateContext()Returns a template key for this log statement, ornullif the statement does not require formatting (in which case the message to be logged can be determined by callinggetLiteralArgument()).longgetTimestampMicros()Deprecated.Use getTimestampNanos()longgetTimestampNanos()Returns a nanosecond timestamp for the current log statement.booleanwasForced()Returns whether this log statement should be emitted regardless of its log level or any other properties.
-
-
-
Method Detail
-
getLevel
Level getLevel()
Returns the log level for the current log statement.
-
getTimestampMicros
@Deprecated long getTimestampMicros()
Deprecated.Use getTimestampNanos()
-
getTimestampNanos
long getTimestampNanos()
Returns a nanosecond timestamp for the current log statement.
-
getLoggerName
String getLoggerName()
Returns the logger name (which is usually a canonicalized class name) ornullif not given.
-
getLogSite
LogSite getLogSite()
Returns the log site data for the current log statement.- Throws:
IllegalStateException- if called prior to the postProcess() method being called.
-
getMetadata
Metadata getMetadata()
Returns any additional metadata for this log statement. If no additional metadata is present, the immutable empty metadata instance is returned.IMPORTANT: The returned instance is restricted to metadata added at the log site, and will not include any scoped metadata to be applied to the log statement. To process combined log site and scoped metadata, obtain or create a
MetadataProcessor.
-
wasForced
boolean wasForced()
Returns whether this log statement should be emitted regardless of its log level or any other properties.This allows extensions of
LogContextorLoggingBackendwhich implement additional filtering or rate-limiting fluent methods to easily check whether a log statement was forced. Forced log statements should behave exactly as if none of the filtering or rate-limiting occurred, including argument validity checks.Thus the idiomatic use of
wasForced()is:public API someFilteringMethod(int value) { if (wasForced()) { return api(); } if (value < 0) { throw new IllegalArgumentException("Bad things ..."); } // rest of method... }Checking for forced log statements before checking the validity of arguments provides a last-resort means to mitigate cases in which syntactically incorrect log statements are only discovered when they are enabled.
-
getTemplateContext
TemplateContext getTemplateContext()
Returns a template key for this log statement, ornullif the statement does not require formatting (in which case the message to be logged can be determined by callinggetLiteralArgument()).
-
getArguments
Object[] getArguments()
Returns the arguments to be formatted with the message. Arguments exist when alog()method with a format message and separate arguments was invoked.- Throws:
IllegalStateException- if no arguments are available (ie, when there is no template context).
-
getLiteralArgument
Object getLiteralArgument()
Returns the single argument to be logged directly when no arguments were provided.- Throws:
IllegalStateException- if no single literal argument is available (ie, when a template context exists).
-
-