Package org.jboss.logmanager
Class ExtLogRecord
- java.lang.Object
-
- java.util.logging.LogRecord
-
- org.jboss.logmanager.ExtLogRecord
-
- All Implemented Interfaces:
Serializable
public class ExtLogRecord extends LogRecord
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExtLogRecord.FormatStyleThe format style to use.
-
Constructor Summary
Constructors Constructor Description ExtLogRecord(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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description 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.ExtLogRecord.FormatStylegetFormatStyle()Get the format style for the record.StringgetFormattedMessage()Deprecated.The formatter should normally be used to format the message contents.StringgetHostName()Get the host name of the record, if known.StringgetLoggerClassName()Get the class name of the logger which created this record.ObjectgetMarker()StringgetMdc(String key)Get the value of an MDC property.Map<String,String>getMdcCopy()Get a copy of all the MDC properties for this log record.StringgetNdc()Get the NDC for this log record.longgetProcessId()Get the process ID of the record, if known.StringgetProcessName()Get the process name of the record, if known.StringgetResourceKey()Get the resource key, if any.StringgetSourceClassName()StringgetSourceFileName()Get the source file name for this log record.intgetSourceLineNumber()Get the source line number for this log record.StringgetSourceMethodName()StringgetSourceModuleName()Get the name of the module that initiated the logging request, if known.StringgetSourceModuleVersion()Get the version of the module that initiated the logging request, if known.StringgetThreadName()Get the thread name of this logging event.StringputMdc(String key, String value)Change an MDC value on this record.StringremoveMdc(String key)Remove an MDC value on this record.voidsetHostName(String hostName)Set the host name of the record.voidsetMarker(Object marker)Set the marker for this event.voidsetMdc(Map<?,?> sourceMap)Create a new MDC using a copy of the source map.voidsetMessage(String message)Set the raw message.voidsetMessage(String message, ExtLogRecord.FormatStyle formatStyle)Set the raw message.voidsetNdc(String value)Change the NDC for this log record.voidsetParameters(Object[] parameters)Set the parameters to the log message.voidsetProcessId(long processId)Set the process ID of the record.voidsetProcessName(String processName)Set the process name of the record.voidsetResourceBundle(ResourceBundle bundle)Set the localization resource bundle.voidsetResourceBundleName(String name)Set the localization resource bundle name.voidsetSourceClassName(String sourceClassName)voidsetSourceFileName(String sourceFileName)Set the source file name for this log record.voidsetSourceLineNumber(int sourceLineNumber)Set the source line number for this log record.voidsetSourceMethodName(String sourceMethodName)voidsetSourceModuleName(String sourceModuleName)Set the source module name of this record.voidsetSourceModuleVersion(String sourceModuleVersion)Set the source module version of this record.voidsetThreadName(String threadName)Set the thread name of this logging event.static ExtLogRecordwrap(LogRecord rec)Wrap a JDK log record.-
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
-
-
-
-
Constructor Detail
-
ExtLogRecord
public ExtLogRecord(Level level, String msg, 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(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
public ExtLogRecord(ExtLogRecord original)
Make a copy of a log record.- Parameters:
original- the original
-
-
Method Detail
-
wrap
public static ExtLogRecord wrap(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
-
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 String getMdc(String key)
Get the value of an MDC property.- Parameters:
key- the property key- Returns:
- the property value
-
getMdcCopy
public Map<String,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 String putMdc(String key, 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 String removeMdc(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(Map<?,?> sourceMap)
Create a new MDC using a copy of the source map.- Parameters:
sourceMap- the source man, must not benull
-
getNdc
public String getNdc()
Get the NDC for this log record.- Returns:
- the NDC
-
setNdc
public void setNdc(String value)
Change the NDC for this log record.- Parameters:
value- the new NDC value
-
getLoggerClassName
public 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
-
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 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(String sourceFileName)
Set the source file name for this log record.- Parameters:
sourceFileName- the source file name
-
getSourceClassName
public String getSourceClassName()
- Overrides:
getSourceClassNamein classLogRecord
-
setSourceClassName
public void setSourceClassName(String sourceClassName)
- Overrides:
setSourceClassNamein classLogRecord
-
getSourceMethodName
public String getSourceMethodName()
- Overrides:
getSourceMethodNamein classLogRecord
-
setSourceMethodName
public void setSourceMethodName(String sourceMethodName)
- Overrides:
setSourceMethodNamein classLogRecord
-
getSourceModuleName
public String getSourceModuleName()
Get the name of the module that initiated the logging request, if known.- Returns:
- the name of the module that initiated the logging request
-
setSourceModuleName
public void setSourceModuleName(String sourceModuleName)
Set the source module name of this record.- Parameters:
sourceModuleName- the source module name
-
getSourceModuleVersion
public String getSourceModuleVersion()
Get the version of the module that initiated the logging request, if known.- Returns:
- the version of the module that initiated the logging request
-
setSourceModuleVersion
public void setSourceModuleVersion(String sourceModuleVersion)
Set the source module version of this record.- Parameters:
sourceModuleVersion- the source module version
-
getFormattedMessage
@Deprecated public String getFormattedMessage()
Deprecated.The formatter should normally be used to format the message contents.Get the fully formatted log record, with resources resolved and parameters applied.- Returns:
- the formatted log record
-
getResourceKey
public String getResourceKey()
Get the resource key, if any. If the log message is not localized, then the key isnull.- Returns:
- the resource key
-
getThreadName
public String getThreadName()
Get the thread name of this logging event.- Returns:
- the thread name
-
setThreadName
public void setThreadName(String threadName)
Set the thread name of this logging event.- Parameters:
threadName- the thread name
-
getHostName
public String getHostName()
Get the host name of the record, if known.- Returns:
- the host name of the record, if known
-
setHostName
public void setHostName(String hostName)
Set the host name of the record.- Parameters:
hostName- the host name of the record
-
getProcessName
public String getProcessName()
Get the process name of the record, if known.- Returns:
- the process name of the record, if known
-
setProcessName
public void setProcessName(String processName)
Set the process name of the record.- Parameters:
processName- the process name of the record
-
getProcessId
public long getProcessId()
Get the process ID of the record, if known.- Returns:
- the process ID of the record, or -1 if not known
-
setProcessId
public void setProcessId(long processId)
Set the process ID of the record.- Parameters:
processId- the process ID of the record
-
setMessage
public void setMessage(String message)
Set the raw message. Any cached formatted message is discarded. The parameter format is set to beMessageFormat-style.- Overrides:
setMessagein classLogRecord- Parameters:
message- the new raw message
-
setMessage
public void setMessage(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(Object[] parameters)
Set the parameters to the log message. Any cached formatted message is discarded.- Overrides:
setParametersin classLogRecord- Parameters:
parameters- the log message parameters. (may be null)
-
setResourceBundle
public void setResourceBundle(ResourceBundle bundle)
Set the localization resource bundle. Any cached formatted message is discarded.- Overrides:
setResourceBundlein classLogRecord- Parameters:
bundle- localization bundle (may be null)
-
setResourceBundleName
public void setResourceBundleName(String name)
Set the localization resource bundle name. Any cached formatted message is discarded.- Overrides:
setResourceBundleNamein classLogRecord- Parameters:
name- localization bundle name (may be null)
-
setMarker
public void setMarker(Object marker)
Set the marker for this event. Markers are used mostly by SLF4J and Log4j.
-
getMarker
public Object getMarker()
-
-