Package java.util.logging
Class LogRecord
- java.lang.Object
-
- java.util.logging.LogRecord
-
- All Implemented Interfaces:
Serializable
public class LogRecord extends Object implements Serializable
ALogRecordobject represents a logging request. It is passed between the logging framework and individual logging handlers. Client applications should not modify aLogRecordobject that has been passed into the logging framework.The
LogRecordclass will infer the source method name and source class name the first time they are accessed if the client application didn't specify them explicitly. This automatic inference is based on the analysis of the call stack and is not guaranteed to be precise. Client applications should force the initialization of these two fields by callinggetSourceClassNameorgetSourceMethodNameif they expect to use them after passing theLogRecordobject to another thread or transmitting it over RMI.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LevelgetLevel()Gets the logging level.StringgetLoggerName()Gets the name of the logger.StringgetMessage()Gets the raw message.longgetMillis()Gets the time when this event occurred, in milliseconds since 1970.Object[]getParameters()Gets the parameters.ResourceBundlegetResourceBundle()Gets the resource bundle used to localize the raw message during formatting.StringgetResourceBundleName()Gets the name of the resource bundle.longgetSequenceNumber()Gets the sequence number.StringgetSourceClassName()Gets the name of the class that is the source of this log record.StringgetSourceMethodName()Gets the name of the method that is the source of this log record.intgetThreadID()Gets a unique ID of the thread originating the log record.ThrowablegetThrown()Gets theThrowableobject associated with this log record.voidsetLevel(Level level)Sets the logging level.voidsetLoggerName(String loggerName)Sets the name of the logger.voidsetMessage(String message)Sets the raw message.voidsetMillis(long millis)Sets the time when this event occurred, in milliseconds since 1970.voidsetParameters(Object[] parameters)Sets the parameters.voidsetResourceBundle(ResourceBundle resourceBundle)Sets the resource bundle used to localize the raw message during formatting.voidsetResourceBundleName(String resourceBundleName)Sets the name of the resource bundle.voidsetSequenceNumber(long sequenceNumber)Sets the sequence number.voidsetSourceClassName(String sourceClassName)Sets the name of the class that is the source of this log record.voidsetSourceMethodName(String sourceMethodName)Sets the name of the method that is the source of this log record.voidsetThreadID(int threadID)Sets the ID of the thread originating this log record.voidsetThrown(Throwable thrown)Sets theThrowableobject associated with this log record.
-
-
-
Constructor Detail
-
LogRecord
public LogRecord(Level level, String msg)
Constructs aLogRecordobject using the supplied the logging level and message. The millis property is set to the current time. The sequence property is set to a new unique value, allocated in increasing order within the VM. The thread ID is set to a unique value for the current thread. All other properties are set tonull.- Parameters:
level- the logging level, may not benull.msg- the raw message.- Throws:
NullPointerException- iflevelisnull.
-
-
Method Detail
-
getLevel
public Level getLevel()
Gets the logging level.- Returns:
- the logging level.
-
setLevel
public void setLevel(Level level)
Sets the logging level.- Parameters:
level- the level to set.- Throws:
NullPointerException- iflevelisnull.
-
getLoggerName
public String getLoggerName()
Gets the name of the logger.- Returns:
- the logger name.
-
setLoggerName
public void setLoggerName(String loggerName)
Sets the name of the logger.- Parameters:
loggerName- the logger name to set.
-
getMessage
public String getMessage()
Gets the raw message.- Returns:
- the raw message, may be
null.
-
setMessage
public void setMessage(String message)
Sets the raw message. When this record is formatted by a logger that has a localization resource bundle that contains an entry formessage, then the raw message is replaced with its localized version.- Parameters:
message- the raw message to set, may benull.
-
getMillis
public long getMillis()
Gets the time when this event occurred, in milliseconds since 1970.- Returns:
- the time when this event occurred, in milliseconds since 1970.
-
setMillis
public void setMillis(long millis)
Sets the time when this event occurred, in milliseconds since 1970.- Parameters:
millis- the time when this event occurred, in milliseconds since 1970.
-
getParameters
public Object[] getParameters()
Gets the parameters.- Returns:
- the array of parameters or
nullif there are no parameters.
-
setParameters
public void setParameters(Object[] parameters)
Sets the parameters.- Parameters:
parameters- the array of parameters to set, may benull.
-
getResourceBundle
public ResourceBundle getResourceBundle()
Gets the resource bundle used to localize the raw message during formatting.- Returns:
- the associated resource bundle,
nullif none is available or the message is not localizable.
-
setResourceBundle
public void setResourceBundle(ResourceBundle resourceBundle)
Sets the resource bundle used to localize the raw message during formatting.- Parameters:
resourceBundle- the resource bundle to set, may benull.
-
getResourceBundleName
public String getResourceBundleName()
Gets the name of the resource bundle.- Returns:
- the name of the resource bundle,
nullif none is available or the message is not localizable.
-
setResourceBundleName
public void setResourceBundleName(String resourceBundleName)
Sets the name of the resource bundle.- Parameters:
resourceBundleName- the name of the resource bundle to set.
-
getSequenceNumber
public long getSequenceNumber()
Gets the sequence number.- Returns:
- the sequence number.
-
setSequenceNumber
public void setSequenceNumber(long sequenceNumber)
Sets the sequence number. It is usually not necessary to call this method to change the sequence number because the number is allocated when this instance is constructed.- Parameters:
sequenceNumber- the sequence number to set.
-
getSourceClassName
public String getSourceClassName()
Gets the name of the class that is the source of this log record. This information can be changed, may benulland is untrusted.- Returns:
- the name of the source class of this log record (possiblity
null)
-
setSourceClassName
public void setSourceClassName(String sourceClassName)
Sets the name of the class that is the source of this log record.- Parameters:
sourceClassName- the name of the source class of this log record, may benull.
-
getSourceMethodName
public String getSourceMethodName()
Gets the name of the method that is the source of this log record.- Returns:
- the name of the source method of this log record.
-
setSourceMethodName
public void setSourceMethodName(String sourceMethodName)
Sets the name of the method that is the source of this log record.- Parameters:
sourceMethodName- the name of the source method of this log record, may benull.
-
getThreadID
public int getThreadID()
Gets a unique ID of the thread originating the log record. Every thread becomes a different ID.Notice : the ID doesn't necessary map the OS thread ID
- Returns:
- the ID of the thread originating this log record.
-
setThreadID
public void setThreadID(int threadID)
Sets the ID of the thread originating this log record.- Parameters:
threadID- the new ID of the thread originating this log record.
-
getThrown
public Throwable getThrown()
Gets theThrowableobject associated with this log record.- Returns:
- the
Throwableobject associated with this log record.
-
setThrown
public void setThrown(Throwable thrown)
Sets theThrowableobject associated with this log record.- Parameters:
thrown- the newThrowableobject to associate with this log record.
-
-