Class LogRecord
- All Implemented Interfaces:
Serializable
public class LogRecord extends Object implements Serializable
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:
Constructor Summary
Constructor | Description |
---|---|
LogRecord |
Construct a LogRecord with the given level and message values. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
Instant |
getInstant() |
Gets the instant that the event occurred. |
Level |
getLevel() |
Get the logging message level, for example Level.SEVERE. |
String |
getLoggerName() |
Get the source Logger's name. |
long |
getLongThreadID() |
Get a thread identifier for the thread where message originated |
String |
getMessage() |
Get the "raw" log message, before localization or formatting. |
long |
getMillis() |
Get truncated event time in milliseconds since 1970. |
Object[] |
getParameters() |
Get the parameters to the log message. |
ResourceBundle |
getResourceBundle() |
Get the localization resource bundle |
String |
getResourceBundleName() |
Get the localization resource bundle name |
long |
getSequenceNumber() |
Get the sequence number. |
String |
getSourceClassName() |
Get the name of the class that (allegedly) issued the logging request. |
String |
getSourceMethodName() |
Get the name of the method that (allegedly) issued the logging request. |
int |
getThreadID() |
Deprecated. |
Throwable |
getThrown() |
Get any throwable associated with the log record. |
void |
setInstant |
Sets the instant that the event occurred. |
void |
setLevel |
Set the logging message level, for example Level.SEVERE. |
void |
setLoggerName |
Set the source Logger's name. |
LogRecord |
setLongThreadID |
Set an identifier for the thread where the message originated. |
void |
setMessage |
Set the "raw" log message, before localization or formatting. |
void |
setMillis |
Deprecated. LogRecord maintains timestamps with nanosecond resolution, using Instant values. |
void |
setParameters |
Set the parameters to the log message. |
void |
setResourceBundle |
Set the localization resource bundle. |
void |
setResourceBundleName |
Set the localization resource bundle name. |
void |
setSequenceNumber |
Set the sequence number. |
void |
setSourceClassName |
Set the name of the class that (allegedly) issued the logging request. |
void |
setSourceMethodName |
Set the name of the method that (allegedly) issued the logging request. |
void |
setThreadID |
Deprecated. This method doesn't allow to pass a long thread id, use setLongThreadID(long) instead. |
void |
setThrown |
Set a throwable associated with the log event. |
Constructor Details
LogRecord
public LogRecord(Level level, String msg)
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:
Method Details
getLoggerName
public String getLoggerName()
- Returns:
- source logger name (may be null)
setLoggerName
public void setLoggerName(String name)
- Parameters:
-
name
- the source logger name (may be null)
getResourceBundle
public ResourceBundle getResourceBundle()
This 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
setResourceBundle
public void setResourceBundle(ResourceBundle bundle)
- Parameters:
-
bundle
- localization bundle (may be null)
getResourceBundleName
public String getResourceBundleName()
This 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
setResourceBundleName
public void setResourceBundleName(String name)
- Parameters:
-
name
- localization bundle name (may be null)
getLevel
public Level getLevel()
- Returns:
- the logging message level
setLevel
public void setLevel(Level level)
- Parameters:
-
level
- the logging message level
getSequenceNumber
public long getSequenceNumber()
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
setSequenceNumber
public void setSequenceNumber(long seq)
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
getSourceClassName
public String getSourceClassName()
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
setSourceClassName
public void setSourceClassName(String sourceClassName)
- Parameters:
-
sourceClassName
- the source class name (may be null)
getSourceMethodName
public String getSourceMethodName()
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
setSourceMethodName
public void setSourceMethodName(String sourceMethodName)
- Parameters:
-
sourceMethodName
- the source method name (may be null)
getMessage
public String getMessage()
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
setMessage
public void setMessage(String message)
- Parameters:
-
message
- the raw message string (may be null)
getParameters
public Object[] getParameters()
- Returns:
- the log message parameters. May be null if there are no parameters.
setParameters
public void setParameters(Object[] parameters)
- Parameters:
-
parameters
- the log message parameters. (may be null)
getThreadID
@Deprecated(since="16") public int getThreadID()
getLongThreadID()
instead.This is a thread identifier within the Java VM and may or may not map to any operating system ID.
- Returns:
- thread ID
setThreadID
@Deprecated(since="16") public void setThreadID(int threadID)
setLongThreadID(long)
instead.- Parameters:
-
threadID
- the thread ID
getLongThreadID
public long getLongThreadID()
This is a thread identifier within the Java VM and may or may not map to any operating system ID.
- Returns:
- thread ID
- Since:
- 16
setLongThreadID
public LogRecord setLongThreadID(long longThreadID)
- Parameters:
-
longThreadID
- the thread ID - Returns:
- this LogRecord
- Since:
- 16
getMillis
public long getMillis()
- 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:
setMillis
@Deprecated public void setMillis(long millis)
Instant
values. For this reason, setInstant()
should be used in preference to setMillis()
.- Implementation Requirements:
- This is equivalent to calling
setInstant(Instant.ofEpochMilli(millis))
. - Parameters:
-
millis
- event time in millis since 1970. - See Also:
getInstant
public Instant getInstant()
- Returns:
- the instant that the event occurred.
- Since:
- 9
setInstant
public void setInstant(Instant instant)
If the given instant
represents a point on the time-line too far in the future or past to fit in a long
milliseconds and nanoseconds adjustment, then an ArithmeticException
will be thrown.
- Parameters:
-
instant
- the instant that the event occurred. - Throws:
-
NullPointerException
- ifinstant
is null. -
ArithmeticException
- if numeric overflow would occur while callinginstant.toEpochMilli()
. - Since:
- 9
getThrown
public Throwable getThrown()
If the event involved an exception, this will be the exception object. Otherwise null.
- Returns:
- a throwable
setThrown
public void setThrown(Throwable thrown)
- Parameters:
-
thrown
- a throwable (may be null)
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.logging/java/util/logging/LogRecord.html
getLongThreadID()
instead.