Most visited

Recently visited

Added in API level 1

LogRecord

public class LogRecord
extends Object implements Serializable

java.lang.Object
   ↳ java.util.logging.LogRecord


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:

Summary

Public constructors

LogRecord(Level level, String msg)

Construct a LogRecord with the given level and message values.

Public methods

Level getLevel()

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

String getLoggerName()

Get the source Logger's name.

String getMessage()

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

long getMillis()

Get event time in milliseconds since 1970.

Object[] getParameters()

Get the parameters to the log message.

ResourceBundle getResourceBundle()

Get the localization resource bundle

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

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.

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()

Get an identifier for the thread where the message originated.

Throwable getThrown()

Get any throwable associated with the log record.

void setLevel(Level level)

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

void setLoggerName(String name)

Set the source Logger's name.

void setMessage(String message)

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

void setMillis(long millis)

Set event time.

void setParameters(Object[] parameters)

Set the parameters to the log message.

void setResourceBundle(ResourceBundle bundle)

Set the localization resource bundle.

void setResourceBundleName(String name)

Set the localization resource bundle name.

void setSequenceNumber(long seq)

Set the sequence number.

void setSourceClassName(String sourceClassName)

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

void setSourceMethodName(String sourceMethodName)

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

void setThreadID(int threadID)

Set an identifier for the thread where the message originated.

void setThrown(Throwable thrown)

Set a throwable associated with the log event.

Inherited methods

From class java.lang.Object

Public constructors

LogRecord

Added in API level 1
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.

The millis property will be initialized to the current time.

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)

Public methods

getLevel

Added in API level 1
Level getLevel ()

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

Returns
Level the logging message level

getLoggerName

Added in API level 1
String getLoggerName ()

Get the source Logger's name.

Returns
String source logger name (may be null)

getMessage

Added in API level 1
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

getMillis

Added in API level 1
long getMillis ()

Get event time in milliseconds since 1970.

Returns
long event time in millis since 1970

getParameters

Added in API level 1
Object[] getParameters ()

Get the parameters to the log message.

Returns
Object[] the log message parameters. May be null if there are no parameters.

getResourceBundle

Added in API level 1
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

getResourceBundleName

Added in API level 1
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

getSequenceNumber

Added in API level 1
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

getSourceClassName

Added in API level 1
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

getSourceMethodName

Added in API level 1
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

getThreadID

Added in API level 1
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
int thread ID

getThrown

Added in API level 1
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

setLevel

Added in API level 1
void setLevel (Level level)

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

Parameters
level Level: the logging message level

setLoggerName

Added in API level 1
void setLoggerName (String name)

Set the source Logger's name.

Parameters
name String: the source logger name (may be null)

setMessage

Added in API level 1
void setMessage (String message)

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

Parameters
message String: the raw message string (may be null)

setMillis

Added in API level 1
void setMillis (long millis)

Set event time.

Parameters
millis long: event time in millis since 1970

setParameters

Added in API level 1
void setParameters (Object[] parameters)

Set the parameters to the log message.

Parameters
parameters Object: the log message parameters. (may be null)

setResourceBundle

Added in API level 1
void setResourceBundle (ResourceBundle bundle)

Set the localization resource bundle.

Parameters
bundle ResourceBundle: localization bundle (may be null)

setResourceBundleName

Added in API level 1
void setResourceBundleName (String name)

Set the localization resource bundle name.

Parameters
name String: localization bundle name (may be null)

setSequenceNumber

Added in API level 1
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

setSourceClassName

Added in API level 1
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)

setSourceMethodName

Added in API level 1
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)

setThreadID

Added in API level 1
void setThreadID (int threadID)

Set an identifier for the thread where the message originated.

Parameters
threadID int: the thread ID

setThrown

Added in API level 1
void setThrown (Throwable thrown)

Set a throwable associated with the log event.

Parameters
thrown Throwable: a throwable (may be null)

Hooray!