Package org.jboss.logmanager
Class ExtLogRecord
java.lang.Object
java.util.logging.LogRecord
org.jboss.logmanager.ExtLogRecord
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
WrappedExtLogRecord
An extended log record, which includes additional information including MDC/NDC and correct
caller location (even in the presence of a logging facade).
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private ExtLogRecord.FormatStyle
private String
private final String
private FastCopyHashMap<String,
Object> private String
private String
private static final long
private String
private int
private String
-
Constructor Summary
ConstructorsConstructorDescriptionExtLogRecord
(Level level, String msg, String loggerClassName) Construct a new instance.ExtLogRecord
(Level level, String msg, ExtLogRecord.FormatStyle formatStyle, String loggerClassName) Construct a new instance.ExtLogRecord
(ExtLogRecord original) Make a copy of a log record. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Find the first stack frame below the call to the logger, and populate the log record with that information.void
copyAll()
Copy all fields and prepare this object to be passed to another thread or to be serialized.void
copyMdc()
Copy the MDC.void
Disable caller calculation for this record.private String
Get the format style for the record.Get the fully formatted log record, with resources resolved and parameters applied.Get the class name of the logger which created this record.Get the value of an MDC property.Get a copy of all the MDC properties for this log record.getNdc()
Get the NDC for this log record.Get the resource key, if any.Get the source file name for this log record.int
Get the source line number for this log record.Get the thread name of this logging event.Change an MDC value on this record.Remove an MDC value on this record.void
Create a new MDC using a copy of the source map.void
setMessage
(String message) Set the raw message.void
setMessage
(String message, ExtLogRecord.FormatStyle formatStyle) Set the raw message.void
Change the NDC for this log record.void
setParameters
(Object[] parameters) Set the parameters to the log message.void
setResourceBundle
(ResourceBundle bundle) Set the localization resource bundle.void
setResourceBundleName
(String name) Set the localization resource bundle name.void
setSourceClassName
(String sourceClassName) void
setSourceFileName
(String sourceFileName) Set the source file name for this log record.void
setSourceLineNumber
(int sourceLineNumber) Set the source line number for this log record.void
setSourceMethodName
(String sourceMethodName) void
setThreadName
(String threadName) Set the thread name of this logging event.private void
static ExtLogRecord
Wrap a JDK log record.private void
Methods inherited from class java.util.logging.LogRecord
getInstant, getLevel, getLoggerName, getLongThreadID, getMessage, getMillis, getParameters, getResourceBundle, getResourceBundleName, getSequenceNumber, getThreadID, getThrown, setInstant, setLevel, setLoggerName, setLongThreadID, setMillis, setSequenceNumber, setThreadID, setThrown
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
loggerClassName
-
calculateCaller
private transient boolean calculateCaller -
ndc
-
formatStyle
-
mdcCopy
-
sourceLineNumber
private int sourceLineNumber -
sourceFileName
-
resourceKey
-
formattedMessage
-
threadName
-
-
Constructor Details
-
ExtLogRecord
Construct a new instance. Grabs the current NDC immediately. MDC is deferred.- Parameters:
level
- a logging level valuemsg
- the raw non-localized logging message (may be null)loggerClassName
- the name of the logger class
-
ExtLogRecord
public ExtLogRecord(Level level, String msg, ExtLogRecord.FormatStyle formatStyle, String loggerClassName) Construct a new instance. Grabs the current NDC immediately. MDC is deferred.- Parameters:
level
- a logging level valuemsg
- the raw non-localized logging message (may be null)formatStyle
- the parameter format style to useloggerClassName
- the name of the logger class
-
ExtLogRecord
Make a copy of a log record.- Parameters:
original
- the original
-
-
Method Details
-
wrap
Wrap a JDK log record. If the target record is already anExtLogRecord
, it is simply returned. Otherwise a wrapper record is created and returned.- Parameters:
rec
- the original record- Returns:
- the wrapped record
-
writeObject
- Throws:
IOException
-
disableCallerCalculation
public void disableCallerCalculation()Disable caller calculation for this record. If the caller has already been calculated, leave it; otherwise set the caller to"unknown"
. -
copyAll
public void copyAll()Copy all fields and prepare this object to be passed to another thread or to be serialized. Calling this method more than once has no additional effect and will not incur extra copies. -
copyMdc
public void copyMdc()Copy the MDC. Call this method before passing this log record to another thread. Calling this method more than once has no additional effect and will not incur extra copies. -
getMdc
Get the value of an MDC property.- Parameters:
key
- the property key- Returns:
- the property value
-
getMdcCopy
Get a copy of all the MDC properties for this log record. If the MDC has not yet been copied, this method will copy it.- Returns:
- a copy of the MDC map
-
putMdc
Change an MDC value on this record. If the MDC has not yet been copied, this method will copy it.- Parameters:
key
- the key to setvalue
- the value to set it to- Returns:
- the old value, if any
-
removeMdc
Remove an MDC value on this record. If the MDC has not yet been copied, this method will copy it.- Parameters:
key
- the key to remove- Returns:
- the old value, if any
-
setMdc
Create a new MDC using a copy of the source map.- Parameters:
sourceMap
- the source man, must not benull
-
getNdc
Get the NDC for this log record.- Returns:
- the NDC
-
setNdc
Change the NDC for this log record.- Parameters:
value
- the new NDC value
-
getLoggerClassName
Get the class name of the logger which created this record.- Returns:
- the class name
-
getFormatStyle
Get the format style for the record.- Returns:
- the format style
-
calculateCaller
private void calculateCaller()Find the first stack frame below the call to the logger, and populate the log record with that information. -
setUnknownCaller
private void setUnknownCaller() -
getSourceLineNumber
public int getSourceLineNumber()Get the source line number for this log record. Note that this line number is not verified and may be spoofed. This information may either have been provided as part of the logging call, or it may have been inferred automatically by the logging framework. In the latter case, the information may only be approximate and may in fact describe an earlier call on the stack frame. May be -1 if no information could be obtained.- Returns:
- the source line number
-
setSourceLineNumber
public void setSourceLineNumber(int sourceLineNumber) Set the source line number for this log record.- Parameters:
sourceLineNumber
- the source line number
-
getSourceFileName
Get the source file name for this log record. Note that this file name is not verified and may be spoofed. This information may either have been provided as part of the logging call, or it may have been inferred automatically by the logging framework. In the latter case, the information may only be approximate and may in fact describe an earlier call on the stack frame. May benull
if no information could be obtained.- Returns:
- the source file name
-
setSourceFileName
Set the source file name for this log record.- Parameters:
sourceFileName
- the source file name
-
getSourceClassName
- Overrides:
getSourceClassName
in classLogRecord
-
setSourceClassName
- Overrides:
setSourceClassName
in classLogRecord
-
getSourceMethodName
- Overrides:
getSourceMethodName
in classLogRecord
-
setSourceMethodName
- Overrides:
setSourceMethodName
in classLogRecord
-
getFormattedMessage
Get the fully formatted log record, with resources resolved and parameters applied.- Returns:
- the formatted log record
-
getResourceKey
Get the resource key, if any. If the log message is not localized, then the key isnull
.- Returns:
- the resource key
-
formatRecord
-
getThreadName
Get the thread name of this logging event.- Returns:
- the thread name
-
setThreadName
Set the thread name of this logging event.- Parameters:
threadName
- the thread name
-
setMessage
Set the raw message. Any cached formatted message is discarded. The parameter format is set to beMessageFormat
-style.- Overrides:
setMessage
in classLogRecord
- Parameters:
message
- the new raw message
-
setMessage
Set the raw message. Any cached formatted message is discarded. The parameter format is set according to the given argument.- Parameters:
message
- the new raw messageformatStyle
- the format style to use
-
setParameters
Set the parameters to the log message. Any cached formatted message is discarded.- Overrides:
setParameters
in classLogRecord
- Parameters:
parameters
- the log message parameters. (may be null)
-
setResourceBundle
Set the localization resource bundle. Any cached formatted message is discarded.- Overrides:
setResourceBundle
in classLogRecord
- Parameters:
bundle
- localization bundle (may be null)
-
setResourceBundleName
Set the localization resource bundle name. Any cached formatted message is discarded.- Overrides:
setResourceBundleName
in classLogRecord
- Parameters:
name
- localization bundle name (may be null)
-