Package org.jboss.logmanager
Class ExtLogRecord
- java.lang.Object
-
- java.util.logging.LogRecord
-
- org.jboss.logmanager.ExtLogRecord
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
WrappedExtLogRecord
public class ExtLogRecord extends java.util.logging.LogRecordAn extended log record, which includes additional information including MDC/NDC and correct caller location (even in the presence of a logging facade).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExtLogRecord.FormatStyleThe format style to use.
-
Field Summary
Fields Modifier and Type Field Description private booleancalculateCallerprivate ExtLogRecord.FormatStyleformatStyleprivate java.lang.StringformattedMessageprivate java.lang.StringloggerClassNameprivate FastCopyHashMap<java.lang.String,java.lang.Object>mdcCopyprivate java.lang.Stringndcprivate java.lang.StringresourceKeyprivate static longserialVersionUIDprivate java.lang.StringsourceFileNameprivate intsourceLineNumberprivate java.lang.StringthreadName
-
Constructor Summary
Constructors Constructor Description ExtLogRecord(java.util.logging.Level level, java.lang.String msg, java.lang.String loggerClassName)Construct a new instance.ExtLogRecord(java.util.logging.Level level, java.lang.String msg, ExtLogRecord.FormatStyle formatStyle, java.lang.String loggerClassName)Construct a new instance.ExtLogRecord(ExtLogRecord original)Make a copy of a log record.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcalculateCaller()Find the first stack frame below the call to the logger, and populate the log record with that information.voidcopyAll()Copy all fields and prepare this object to be passed to another thread or to be serialized.voidcopyMdc()Copy the MDC.voiddisableCallerCalculation()Disable caller calculation for this record.private java.lang.StringformatRecord()ExtLogRecord.FormatStylegetFormatStyle()Get the format style for the record.java.lang.StringgetFormattedMessage()Get the fully formatted log record, with resources resolved and parameters applied.java.lang.StringgetLoggerClassName()Get the class name of the logger which created this record.java.lang.StringgetMdc(java.lang.String key)Get the value of an MDC property.java.util.Map<java.lang.String,java.lang.String>getMdcCopy()Get a copy of all the MDC properties for this log record.java.lang.StringgetNdc()Get the NDC for this log record.java.lang.StringgetResourceKey()Get the resource key, if any.java.lang.StringgetSourceClassName()java.lang.StringgetSourceFileName()Get the source file name for this log record.intgetSourceLineNumber()Get the source line number for this log record.java.lang.StringgetSourceMethodName()java.lang.StringgetThreadName()Get the thread name of this logging event.java.lang.StringputMdc(java.lang.String key, java.lang.String value)Change an MDC value on this record.java.lang.StringremoveMdc(java.lang.String key)Remove an MDC value on this record.voidsetMdc(java.util.Map<?,?> sourceMap)Create a new MDC using a copy of the source map.voidsetMessage(java.lang.String message)Set the raw message.voidsetMessage(java.lang.String message, ExtLogRecord.FormatStyle formatStyle)Set the raw message.voidsetNdc(java.lang.String value)Change the NDC for this log record.voidsetParameters(java.lang.Object[] parameters)Set the parameters to the log message.voidsetResourceBundle(java.util.ResourceBundle bundle)Set the localization resource bundle.voidsetResourceBundleName(java.lang.String name)Set the localization resource bundle name.voidsetSourceClassName(java.lang.String sourceClassName)voidsetSourceFileName(java.lang.String sourceFileName)Set the source file name for this log record.voidsetSourceLineNumber(int sourceLineNumber)Set the source line number for this log record.voidsetSourceMethodName(java.lang.String sourceMethodName)voidsetThreadName(java.lang.String threadName)Set the thread name of this logging event.private voidsetUnknownCaller()static ExtLogRecordwrap(java.util.logging.LogRecord rec)Wrap a JDK log record.private voidwriteObject(java.io.ObjectOutputStream oos)-
Methods inherited from class java.util.logging.LogRecord
getInstant, getLevel, getLoggerName, getMessage, getMillis, getParameters, getResourceBundle, getResourceBundleName, getSequenceNumber, getThreadID, getThrown, setInstant, setLevel, setLoggerName, setMillis, setSequenceNumber, setThreadID, setThrown
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
loggerClassName
private final transient java.lang.String loggerClassName
-
calculateCaller
private transient boolean calculateCaller
-
ndc
private java.lang.String ndc
-
formatStyle
private ExtLogRecord.FormatStyle formatStyle
-
mdcCopy
private FastCopyHashMap<java.lang.String,java.lang.Object> mdcCopy
-
sourceLineNumber
private int sourceLineNumber
-
sourceFileName
private java.lang.String sourceFileName
-
resourceKey
private java.lang.String resourceKey
-
formattedMessage
private java.lang.String formattedMessage
-
threadName
private java.lang.String threadName
-
-
Constructor Detail
-
ExtLogRecord
public ExtLogRecord(java.util.logging.Level level, java.lang.String msg, java.lang.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)loggerClassName- the name of the logger class
-
ExtLogRecord
public ExtLogRecord(java.util.logging.Level level, java.lang.String msg, ExtLogRecord.FormatStyle formatStyle, java.lang.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
public ExtLogRecord(ExtLogRecord original)
Make a copy of a log record.- Parameters:
original- the original
-
-
Method Detail
-
wrap
public static ExtLogRecord wrap(java.util.logging.LogRecord rec)
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
private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException- Throws:
java.io.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
public java.lang.String getMdc(java.lang.String key)
Get the value of an MDC property.- Parameters:
key- the property key- Returns:
- the property value
-
getMdcCopy
public java.util.Map<java.lang.String,java.lang.String> 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
public java.lang.String putMdc(java.lang.String key, java.lang.String value)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
public java.lang.String removeMdc(java.lang.String key)
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
public void setMdc(java.util.Map<?,?> sourceMap)
Create a new MDC using a copy of the source map.- Parameters:
sourceMap- the source man, must not benull
-
getNdc
public java.lang.String getNdc()
Get the NDC for this log record.- Returns:
- the NDC
-
setNdc
public void setNdc(java.lang.String value)
Change the NDC for this log record.- Parameters:
value- the new NDC value
-
getLoggerClassName
public java.lang.String getLoggerClassName()
Get the class name of the logger which created this record.- Returns:
- the class name
-
getFormatStyle
public ExtLogRecord.FormatStyle 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
public java.lang.String 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 benullif no information could be obtained.- Returns:
- the source file name
-
setSourceFileName
public void setSourceFileName(java.lang.String sourceFileName)
Set the source file name for this log record.- Parameters:
sourceFileName- the source file name
-
getSourceClassName
public java.lang.String getSourceClassName()
- Overrides:
getSourceClassNamein classjava.util.logging.LogRecord
-
setSourceClassName
public void setSourceClassName(java.lang.String sourceClassName)
- Overrides:
setSourceClassNamein classjava.util.logging.LogRecord
-
getSourceMethodName
public java.lang.String getSourceMethodName()
- Overrides:
getSourceMethodNamein classjava.util.logging.LogRecord
-
setSourceMethodName
public void setSourceMethodName(java.lang.String sourceMethodName)
- Overrides:
setSourceMethodNamein classjava.util.logging.LogRecord
-
getFormattedMessage
public java.lang.String getFormattedMessage()
Get the fully formatted log record, with resources resolved and parameters applied.- Returns:
- the formatted log record
-
getResourceKey
public java.lang.String getResourceKey()
Get the resource key, if any. If the log message is not localized, then the key isnull.- Returns:
- the resource key
-
formatRecord
private java.lang.String formatRecord()
-
getThreadName
public java.lang.String getThreadName()
Get the thread name of this logging event.- Returns:
- the thread name
-
setThreadName
public void setThreadName(java.lang.String threadName)
Set the thread name of this logging event.- Parameters:
threadName- the thread name
-
setMessage
public void setMessage(java.lang.String message)
Set the raw message. Any cached formatted message is discarded. The parameter format is set to beMessageFormat-style.- Overrides:
setMessagein classjava.util.logging.LogRecord- Parameters:
message- the new raw message
-
setMessage
public void setMessage(java.lang.String message, ExtLogRecord.FormatStyle formatStyle)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
public void setParameters(java.lang.Object[] parameters)
Set the parameters to the log message. Any cached formatted message is discarded.- Overrides:
setParametersin classjava.util.logging.LogRecord- Parameters:
parameters- the log message parameters. (may be null)
-
setResourceBundle
public void setResourceBundle(java.util.ResourceBundle bundle)
Set the localization resource bundle. Any cached formatted message is discarded.- Overrides:
setResourceBundlein classjava.util.logging.LogRecord- Parameters:
bundle- localization bundle (may be null)
-
setResourceBundleName
public void setResourceBundleName(java.lang.String name)
Set the localization resource bundle name. Any cached formatted message is discarded.- Overrides:
setResourceBundleNamein classjava.util.logging.LogRecord- Parameters:
name- localization bundle name (may be null)
-
-