Top Description Inners Fields Constructors Methods
java.util.logging

public Class LogRecord

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.time.Instant, .Clock, java.util.*, java.util.concurrent.atomic.AtomicLong, java.io.*, java.security.AccessController, .PrivilegedAction, java.util.function.Predicate

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:

Since
1.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final AtomicLong
private Instant
instant

Event time.

private Level
level

Logging message level

private String
loggerName

Name of the source Logger.

private long
longThreadID

long value of Thread ID for thread that issued logging call.

private String
message

Non-localized raw message text

private transient boolean
private transient Object[]
private transient ResourceBundle
private String
resourceBundleName

Resource bundle name to localized log message.

private long
sequenceNumber

Sequence number

private static final ObjectStreamField[]
private static final long
private String
sourceClassName

Class that issued logging call

private String
sourceMethodName

Method that issued logging call

private int
threadID

Thread ID for thread that issued logging call.

private Throwable
thrown

The Throwable (if any) associated with log message

Constructor Summary

AccessConstructor and Description
public
LogRecord(Level
a logging level value
level
,
String
the raw non-localized logging message (may be null)
msg
)

Construct a LogRecord with the given level and message values.

Method Summary

Modifier and TypeMethod and Description
public Instant

Returns:

the instant that the event occurred.
getInstant
()

Gets the instant that the event occurred.

public Level

Returns:

the logging message level
getLevel
()

Get the logging message level, for example Level.SEVERE.

public String

Returns:

source logger name (may be null)
getLoggerName
()

Get the source Logger's name.

public long

Returns:

thread ID
getLongThreadID
()

Get a thread identifier for the thread where message originated

This is a thread identifier within the Java VM and may or may not map to any operating system ID.

public String

Returns:

the raw message string
getMessage
()

Get the "raw" log message, before localization or formatting.

public long

Returns:

truncated event time in millis since 1970
getMillis
()

Get truncated event time in milliseconds since 1970.

public Object[]

Returns:

the log message parameters. May be null if there are no parameters.
getParameters
()

Get the parameters to the log message.

public ResourceBundle

Returns:

the localization resource bundle
getResourceBundle
()

Get the localization resource bundle

This is the ResourceBundle that should be used to localize the message string before formatting it.

public String

Returns:

the localization resource bundle name
getResourceBundleName
()

Get the localization resource bundle name

This is the name for the ResourceBundle that should be used to localize the message string before formatting it.

public long

Returns:

the sequence number
getSequenceNumber
()

Get the sequence number.

public String

Returns:

the source class name
getSourceClassName
()

Get the name of the class that (allegedly) issued the logging request.

public String

Returns:

the source method name
getSourceMethodName
()

Get the name of the method that (allegedly) issued the logging request.

public int

Returns:

thread ID
getThreadID
()
Deprecated since 16. Values returned by this method may be synthesized, and may not correspond to the actual thread id, use getLongThreadID() instead.

Get an identifier for the thread where the message originated.

public Throwable

Returns:

a throwable
getThrown
()

Get any throwable associated with the log record.

private void
private void
readObject(ObjectInputStream
the ObjectInputStream to read from
in
)

Initializes the LogRecord from deserialized data.

public void
setInstant(Instant
the instant that the event occurred.
instant
)

Sets the instant that the event occurred.

public void
setLevel(Level
the logging message level
level
)

Set the logging message level, for example Level.SEVERE.

public void
setLoggerName(String
the source logger name (may be null)
name
)

Set the source Logger's name.

public LogRecord

Returns:

this LogRecord
setLongThreadID
(long
the thread ID
longThreadID
)

Set an identifier for the thread where the message originated.

public void
setMessage(String
the raw message string (may be null)
message
)

Set the "raw" log message, before localization or formatting.

public void
setMillis(long
event time in millis since 1970.
millis
)
Deprecated LogRecord maintains timestamps with nanosecond resolution, using Instant values.

Set event time.

public void
setParameters(Object[]
the log message parameters. (may be null)
parameters
)

Set the parameters to the log message.

public void
setResourceBundle(ResourceBundle
localization bundle (may be null)
bundle
)

Set the localization resource bundle.

public void
setResourceBundleName(String
localization bundle name (may be null)
name
)

Set the localization resource bundle name.

public void
setSequenceNumber(long
the sequence number
seq
)

Set the sequence number.

public void
setSourceClassName(String
the source class name (may be null)
sourceClassName
)

Set the name of the class that (allegedly) issued the logging request.

public void
setSourceMethodName(String
the source method name (may be null)
sourceMethodName
)

Set the name of the method that (allegedly) issued the logging request.

public void
setThreadID(int
the thread ID
threadID
)
Deprecated since 16. This method doesn't allow to pass a long thread id, use setLongThreadID(long) instead.

Set an identifier for the thread where the message originated.

public void
setThrown(Throwable
a throwable (may be null)
thrown
)

Set a throwable associated with the log event.

private int

Returns:

thread id
shortThreadID
(long id)

Synthesizes a pseudo unique integer value from a long id value.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write to
out
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

globalSequenceNumberback to summary
private static final AtomicLong globalSequenceNumber
instantback to summary
private Instant instant

Event time.

Since
9
levelback to summary
private Level level

Logging message level

loggerNameback to summary
private String loggerName

Name of the source Logger.

longThreadIDback to summary
private long longThreadID

long value of Thread ID for thread that issued logging call.

messageback to summary
private String message

Non-localized raw message text

needToInferCallerback to summary
private transient boolean needToInferCaller
parametersback to summary
private transient Object[] parameters
resourceBundleback to summary
private transient ResourceBundle resourceBundle
resourceBundleNameback to summary
private String resourceBundleName

Resource bundle name to localized log message.

sequenceNumberback to summary
private long sequenceNumber

Sequence number

serialPersistentFieldsback to summary
private static final ObjectStreamField[] serialPersistentFields
Annotations
@Serial
Serial Fields:
level:Level
Logging message level
sequenceNumber:long
Sequence number
sourceClassName:String
Class that issued logging call
sourceMethodName:String
Method that issued logging call
message:String
Non-localized raw message text
threadID:int
this is deprecated and is available for backward compatibility. Values may have been synthesized. If present, longThreadID represents the actual thread id.
longThreadID:long
Thread ID for thread that issued logging call
millis:long
Truncated event time in milliseconds since 1970 - calculated as getInstant().toEpochMilli(). The event time instant can be reconstructed using Instant.ofEpochSecond(millis/1000, (millis % 1000) * 1000_000 + nanoAdjustment)
nanoAdjustment:int
Nanoseconds adjustment to the millisecond of event time - calculated as getInstant().getNano() % 1000_000 The event time instant can be reconstructed using Instant.ofEpochSecond(millis/1000, (millis % 1000) * 1000_000 + nanoAdjustment)

Since: 9

thrown:Throwable
The Throwable (if any) associated with log message
loggerName:String
Name of the source Logger
resourceBundleName:String
Resource bundle name to localized log message
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
sourceClassNameback to summary
private String sourceClassName

Class that issued logging call

sourceMethodNameback to summary
private String sourceMethodName

Method that issued logging call

threadIDback to summary
private int threadID

Thread ID for thread that issued logging call.

thrownback to summary
private Throwable thrown

The Throwable (if any) associated with log message

Constructor Detail

LogRecordback to summary
public 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:Level

a logging level value

msg:String

the raw non-localized logging message (may be null)

See Also
java.time.Clock#systemUTC()

Method Detail

getInstantback to summary
public Instant getInstant()

Gets the instant that the event occurred.

Returns:Instant

the instant that the event occurred.

Since
9
getLevelback to summary
public Level getLevel()

Get the logging message level, for example Level.SEVERE.

Returns:Level

the logging message level

getLoggerNameback to summary
public String getLoggerName()

Get the source Logger's name.

Returns:String

source logger name (may be null)

getLongThreadIDback to summary
public long getLongThreadID()

Get a thread identifier for the thread where message originated

This is a thread identifier within the Java VM and may or may not map to any operating system ID.

Returns:long

thread ID

Since
16
getMessageback to summary
public 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:String

the raw message string

getMillisback to summary
public long getMillis()

Get truncated event time in milliseconds since 1970.

Implementation Specification

This is equivalent to calling getInstant().toEpochMilli().

API Note

To get the full nanosecond resolution event time, use getInstant().

Returns:long

truncated event time in millis since 1970

See Also
getInstant()
getParametersback to summary
public Object[] getParameters()

Get the parameters to the log message.

Returns:Object[]

the log message parameters. May be null if there are no parameters.

getResourceBundleback to summary
public ResourceBundle getResourceBundle()

Get the localization resource bundle

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:ResourceBundle

the localization resource bundle

getResourceBundleNameback to summary
public String getResourceBundleName()

Get the localization resource bundle name

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:String

the localization resource bundle name

getSequenceNumberback to summary
public 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:long

the sequence number

getSourceClassNameback to summary
public 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:String

the source class name

getSourceMethodNameback to summary
public 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:String

the source method name

getThreadIDback to summary
public int getThreadID()

Deprecated

since 16.

Values returned by this method may be synthesized, and may not correspond to the actual thread id, use getLongThreadID() instead.

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:int

thread ID

Annotations
@Deprecated
since:16
getThrownback to summary
public 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:Throwable

a throwable

inferCallerback to summary
private void inferCaller()
readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException

Initializes the LogRecord from deserialized data.

  • If longThreadID is present in the serial form, its value takes precedence over threadID and a value for threadID is synthesized from it, such that for longThreadID values between 0 and Integer.MAX_VALUE inclusive, longThreadID and threadID will have the same value. For values outside of this range a negative synthesized value will be deterministically derived from longThreadID.
  • Otherwise, when only threadID is present, longThreadID is initialized with the value of threadID which may be anything between Integer.MIN_VALUE and {Integer.MAX_VALUE}.
See writeObject for a description of the serial form.
Parameters
in:ObjectInputStream

the ObjectInputStream to read from

Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs.
ClassNotFoundException:
if the class of a serialized object could not be found.
setInstantback to summary
public void setInstant(Instant instant)

Sets the instant that the event occurred.

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:Instant

the instant that the event occurred.

Exceptions
NullPointerException:
if instant is null.
ArithmeticException:
if numeric overflow would occur while calling instant.toEpochMilli().
Since
9
setLevelback to summary
public void setLevel(Level level)

Set the logging message level, for example Level.SEVERE.

Parameters
level:Level

the logging message level

setLoggerNameback to summary
public void setLoggerName(String name)

Set the source Logger's name.

Parameters
name:String

the source logger name (may be null)

setLongThreadIDback to summary
public LogRecord setLongThreadID(long longThreadID)

Set an identifier for the thread where the message originated.

Parameters
longThreadID:long

the thread ID

Returns:LogRecord

this LogRecord

Since
16
setMessageback to summary
public void setMessage(String message)

Set the "raw" log message, before localization or formatting.

Parameters
message:String

the raw message string (may be null)

setMillisback to summary
public void setMillis(long millis)

Deprecated

LogRecord maintains timestamps with nanosecond resolution, using Instant values. For this reason, setInstant() should be used in preference to setMillis().

Set event time.

Implementation Specification

This is equivalent to calling setInstant(Instant.ofEpochMilli(millis)).

Parameters
millis:long

event time in millis since 1970.

Annotations
@Deprecated
See Also
setInstant(java.time.Instant)
setParametersback to summary
public void setParameters(Object[] parameters)

Set the parameters to the log message.

Parameters
parameters:Object[]

the log message parameters. (may be null)

setResourceBundleback to summary
public void setResourceBundle(ResourceBundle bundle)

Set the localization resource bundle.

Parameters
bundle:ResourceBundle

localization bundle (may be null)

setResourceBundleNameback to summary
public void setResourceBundleName(String name)

Set the localization resource bundle name.

Parameters
name:String

localization bundle name (may be null)

setSequenceNumberback to summary
public 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:long

the sequence number

setSourceClassNameback to summary
public void setSourceClassName(String sourceClassName)

Set the name of the class that (allegedly) issued the logging request.

Parameters
sourceClassName:String

the source class name (may be null)

setSourceMethodNameback to summary
public void setSourceMethodName(String sourceMethodName)

Set the name of the method that (allegedly) issued the logging request.

Parameters
sourceMethodName:String

the source method name (may be null)

setThreadIDback to summary
public void setThreadID(int threadID)

Deprecated

since 16.

This method doesn't allow to pass a long thread id, use setLongThreadID(long) instead.

Set an identifier for the thread where the message originated.

Parameters
threadID:int

the thread ID

Annotations
@Deprecated
since:16
setThrownback to summary
public void setThrown(Throwable thrown)

Set a throwable associated with the log event.

Parameters
thrown:Throwable

a throwable (may be null)

shortThreadIDback to summary
private int shortThreadID(long id)

Synthesizes a pseudo unique integer value from a long id value. For backward compatibility with previous releases, the returned integer is such that for any positive long less than or equals to Integer.MAX_VALUE, the returned integer is equal to the original value. Otherwise - it is synthesized with a best effort hashing algorithm, and the returned value is negative. Calling this method multiple times with the same value always yields the same result.

Returns:int

thread id

writeObjectback to summary
private void writeObject(ObjectOutputStream out) throws IOException
Parameters
out:ObjectOutputStream

the ObjectOutputStream to write to

Annotations
@Serial
Exceptions
IOException:
if I/O errors occur
Serial data
Serialized fields, followed by a two byte version number (major byte, followed by minor byte), followed by information on the log record parameter array. If there is no parameter array, then -1 is written. If there is a parameter array (possible of zero length) then the array length is written as an integer, followed by String values for each parameter. If a parameter is null, then a null String is written. Otherwise the output of Object.toString() is written.
java.util.logging back to summary

pack-priv final Class LogRecord.CallerFinder

extends Object
implements Predicate<StackWalker.StackFrame>
Class Inheritance
All Implemented Interfaces
java.util.function.Predicate
Annotations
@SuppressWarnings:removal

Field Summary

Modifier and TypeField and Description
private boolean
private static final StackWalker

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv Optional<StackWalker.StackFrame>

Returns:

StackFrame of the caller's frame.
get
()

Returns StackFrame of the caller's frame.

private boolean
public boolean

Returns:

true if we have found the caller's frame, false if the frame must be skipped.
test
(StackWalker.StackFrame
The frame info.
t
)

Implements java.util.function.Predicate.test.

Returns true if we have found the caller's frame, false if the frame must be skipped.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lookingForLoggerback to summary
private boolean lookingForLogger
WALKERback to summary
private static final StackWalker WALKER

Constructor Detail

CallerFinderback to summary
pack-priv CallerFinder()

Method Detail

getback to summary
pack-priv Optional<StackWalker.StackFrame> get()

Returns StackFrame of the caller's frame.

Returns:Optional<StackWalker.StackFrame>

StackFrame of the caller's frame.

isLoggerImplFrameback to summary
private boolean isLoggerImplFrame(String cname)
testback to summary
public boolean test(StackWalker.StackFrame t)

Implements java.util.function.Predicate.test.

Returns true if we have found the caller's frame, false if the frame must be skipped.

Parameters
t:StackWalker.StackFrame

The frame info.

Returns:boolean

true if we have found the caller's frame, false if the frame must be skipped.

Annotations
@Override