- java.lang.Object
- 
- java.util.logging.LogRecord
 
- 
- All Implemented Interfaces:
- Serializable
 
 public class LogRecord extends Object implements Serializable LogRecord objects are used to pass logging requests between the logging framework and individual log Handlers.When a LogRecord is passed into the logging framework it logically belongs to the framework and should no longer be used or updated by the client application. Note that if the client application has not specified an explicit source method name and source class name, then the LogRecord class will infer them automatically when they are first accessed (due to a call on getSourceMethodName or getSourceClassName) by analyzing the call stack. Therefore, if a logging Handler wants to pass off a LogRecord to another thread, or to transmit it over RMI, and if it wishes to subsequently obtain method name or class name information it should call one of getSourceClassName or getSourceMethodName to force the values to be filled in. Serialization notes: - The LogRecord class is serializable.
- Because objects in the parameters array may not be serializable, during serialization all objects in the parameters array are written as the corresponding Strings (using Object.toString).
- The ResourceBundle is not transmitted as part of the serialized form, but the resource bundle name is, and the recipient object's readObject method will attempt to locate a suitable resource bundle.
 - Since:
- 1.4
- See Also:
- Serialized Form
 
- 
- 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description InstantgetInstant()Gets the instant that the event occurred.LevelgetLevel()Get the logging message level, for example Level.SEVERE.StringgetLoggerName()Get the source Logger's name.StringgetMessage()Get the "raw" log message, before localization or formatting.longgetMillis()Get truncated event time in milliseconds since 1970.Object[]getParameters()Get the parameters to the log message.ResourceBundlegetResourceBundle()Get the localization resource bundleStringgetResourceBundleName()Get the localization resource bundle namelonggetSequenceNumber()Get the sequence number.StringgetSourceClassName()Get the name of the class that (allegedly) issued the logging request.StringgetSourceMethodName()Get the name of the method that (allegedly) issued the logging request.intgetThreadID()Get an identifier for the thread where the message originated.ThrowablegetThrown()Get any throwable associated with the log record.voidsetInstant(Instant instant)Sets the instant that the event occurred.voidsetLevel(Level level)Set the logging message level, for example Level.SEVERE.voidsetLoggerName(String name)Set the source Logger's name.voidsetMessage(String message)Set the "raw" log message, before localization or formatting.voidsetMillis(long millis)Deprecated.LogRecord maintains timestamps with nanosecond resolution, usingInstantvalues.voidsetParameters(Object[] parameters)Set the parameters to the log message.voidsetResourceBundle(ResourceBundle bundle)Set the localization resource bundle.voidsetResourceBundleName(String name)Set the localization resource bundle name.voidsetSequenceNumber(long seq)Set the sequence number.voidsetSourceClassName(String sourceClassName)Set the name of the class that (allegedly) issued the logging request.voidsetSourceMethodName(String sourceMethodName)Set the name of the method that (allegedly) issued the logging request.voidsetThreadID(int threadID)Set an identifier for the thread where the message originated.voidsetThrown(Throwable thrown)Set a throwable associated with the log event.
 
- 
- 
- 
Constructor Detail- 
LogRecordpublic LogRecord(Level level, String msg) Construct a LogRecord with the given level and message values.The sequence property will be initialized with a new unique value. These sequence values are allocated in increasing order within a VM. Since JDK 9, the event time is represented by an Instant. The instant property will be initialized to the current instant, using the best available clock on the system.The thread ID property will be initialized with a unique ID for the current thread. All other properties will be initialized to "null". - Parameters:
- level- a logging level value
- msg- the raw non-localized logging message (may be null)
- See Also:
- Clock.systemUTC()
 
 
- 
 - 
Method Detail- 
getLoggerNamepublic String getLoggerName() Get the source Logger's name.- Returns:
- source logger name (may be null)
 
 - 
setLoggerNamepublic void setLoggerName(String name) Set the source Logger's name.- Parameters:
- name- the source logger name (may be null)
 
 - 
getResourceBundlepublic ResourceBundle getResourceBundle() Get the localization resource bundleThis is the ResourceBundle that should be used to localize the message string before formatting it. The result may be null if the message is not localizable, or if no suitable ResourceBundle is available. - Returns:
- the localization resource bundle
 
 - 
setResourceBundlepublic void setResourceBundle(ResourceBundle bundle) Set the localization resource bundle.- Parameters:
- bundle- localization bundle (may be null)
 
 - 
getResourceBundleNamepublic String getResourceBundleName() Get the localization resource bundle nameThis is the name for the ResourceBundle that should be used to localize the message string before formatting it. The result may be null if the message is not localizable. - Returns:
- the localization resource bundle name
 
 - 
setResourceBundleNamepublic void setResourceBundleName(String name) Set the localization resource bundle name.- Parameters:
- name- localization bundle name (may be null)
 
 - 
getLevelpublic Level getLevel() Get the logging message level, for example Level.SEVERE.- Returns:
- the logging message level
 
 - 
setLevelpublic void setLevel(Level level) Set the logging message level, for example Level.SEVERE.- Parameters:
- level- the logging message level
 
 - 
getSequenceNumberpublic long getSequenceNumber() Get the sequence number.Sequence numbers are normally assigned in the LogRecord constructor, which assigns unique sequence numbers to each new LogRecord in increasing order. - Returns:
- the sequence number
 
 - 
setSequenceNumberpublic void setSequenceNumber(long seq) Set the sequence number.Sequence numbers are normally assigned in the LogRecord constructor, so it should not normally be necessary to use this method. - Parameters:
- seq- the sequence number
 
 - 
getSourceClassNamepublic String getSourceClassName() Get the name of the class that (allegedly) issued the logging request.Note that this sourceClassName 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 null if no information could be obtained. - Returns:
- the source class name
 
 - 
setSourceClassNamepublic void setSourceClassName(String sourceClassName) Set the name of the class that (allegedly) issued the logging request.- Parameters:
- sourceClassName- the source class name (may be null)
 
 - 
getSourceMethodNamepublic String getSourceMethodName() Get the name of the method that (allegedly) issued the logging request.Note that this sourceMethodName 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 null if no information could be obtained. - Returns:
- the source method name
 
 - 
setSourceMethodNamepublic void setSourceMethodName(String sourceMethodName) Set the name of the method that (allegedly) issued the logging request.- Parameters:
- sourceMethodName- the source method name (may be null)
 
 - 
getMessagepublic String getMessage() Get the "raw" log message, before localization or formatting.May be null, which is equivalent to the empty string "". This message may be either the final text or a localization key. During formatting, if the source logger has a localization ResourceBundle and if that ResourceBundle has an entry for this message string, then the message string is replaced with the localized value. - Returns:
- the raw message string
 
 - 
setMessagepublic void setMessage(String message) Set the "raw" log message, before localization or formatting.- Parameters:
- message- the raw message string (may be null)
 
 - 
getParameterspublic Object[] getParameters() Get the parameters to the log message.- Returns:
- the log message parameters. May be null if there are no parameters.
 
 - 
setParameterspublic void setParameters(Object[] parameters) Set the parameters to the log message.- Parameters:
- parameters- the log message parameters. (may be null)
 
 - 
getThreadIDpublic int getThreadID() Get an identifier for the thread where the message originated.This is a thread identifier within the Java VM and may or may not map to any operating system ID. - Returns:
- thread ID
 
 - 
setThreadIDpublic void setThreadID(int threadID) Set an identifier for the thread where the message originated.- Parameters:
- threadID- the thread ID
 
 - 
getMillispublic long getMillis() Get truncated event time in milliseconds since 1970.- API Note:
- To get the full nanosecond resolution event time,
             use getInstant().
- Implementation Requirements:
- This is equivalent to calling
      getInstant().toEpochMilli().
- Returns:
- truncated event time in millis since 1970
- See Also:
- getInstant()
 
 - 
setMillis@Deprecated public void setMillis(long millis) Deprecated.LogRecord maintains timestamps with nanosecond resolution, usingInstantvalues. For this reason,setInstant()should be used in preference tosetMillis().Set event time.- Implementation Requirements:
- This is equivalent to calling
      setInstant(Instant.ofEpochMilli(millis)).
- Parameters:
- millis- event time in millis since 1970.
- See Also:
- setInstant(java.time.Instant)
 
 - 
getInstantpublic Instant getInstant() Gets the instant that the event occurred.- Returns:
- the instant that the event occurred.
- Since:
- 9
 
 - 
setInstantpublic void setInstant(Instant instant) Sets the instant that the event occurred.If the given instantrepresents a point on the time-line too far in the future or past to fit in alongmilliseconds and nanoseconds adjustment, then anArithmeticExceptionwill be thrown.- Parameters:
- instant- the instant that the event occurred.
- Throws:
- NullPointerException- if- instantis null.
- ArithmeticException- if numeric overflow would occur while calling- instant.toEpochMilli().
- Since:
- 9
 
 - 
getThrownpublic Throwable getThrown() Get any throwable associated with the log record.If the event involved an exception, this will be the exception object. Otherwise null. - Returns:
- a throwable
 
 - 
setThrownpublic void setThrown(Throwable thrown) Set a throwable associated with the log event.- Parameters:
- thrown- a throwable (may be null)
 
 
- 
 
-