java.util.logging

Class LogRecord

Implemented Interfaces:
Serializable

public class LogRecord
extends Object
implements Serializable

A LogRecord contains the state for an individual event to be logged.

As soon as a LogRecord instance has been handed over to the logging framework, applications should not manipulate it anymore.

See Also:
Serialized Form

Constructor Summary

LogRecord(Level level, String message)
Constructs a LogRecord given a severity level and an unlocalized message text.

Method Summary

Level
getLevel()
Returns the level of the LogRecord.
String
getLoggerName()
Returns the name of the logger where this LogRecord has originated.
String
getMessage()
Returns the message for this LogRecord before any localization or parameter substitution.
long
getMillis()
Returns the time when this LogRecord was created.
Object[]
getParameters()
Returns the parameters to the log message.
ResourceBundle
getResourceBundle()
Returns the resource bundle that is used when the message of this LogRecord needs to be localized.
String
getResourceBundleName()
Returns the name of the resource bundle that is used when the message of this LogRecord needs to be localized.
long
getSequenceNumber()
Returns the sequence number of this LogRecord.
String
getSourceClassName()
Returns the name of the class where the event being logged has had its origin.
String
getSourceMethodName()
Returns the name of the method where the event being logged has had its origin.
int
getThreadID()
Returns an identifier for the thread in which this LogRecord was created.
Throwable
getThrown()
Returns the Throwable associated with this LogRecord, or null if the logged event is not related to an exception or error.
void
setLevel(Level level)
Sets the severity level of this LogRecord to a new value.
void
setLoggerName(String name)
Sets the name of the logger where this LogRecord has originated.
void
setMessage(String message)
Sets the message for this LogRecord.
void
setMillis(long millis)
Sets the time when this LogRecord was created.
void
setParameters(Object[] parameters)
Sets the parameters to the log message.
void
setResourceBundle(ResourceBundle bundle)
Sets the resource bundle that is used when the message of this LogRecord needs to be localized.
void
setResourceBundleName(String name)
Sets the name of the resource bundle that is used when the message of this LogRecord needs to be localized.
void
setSequenceNumber(long seqNum)
Sets the sequence number of this LogRecord to a new value.
void
setSourceClassName(String sourceClassName)
Sets the name of the class where the event being logged has had its origin.
void
setSourceMethodName(String sourceMethodName)
Sets the name of the method where the event being logged has had its origin.
void
setThreadID(int threadID)
Sets the identifier indicating in which thread this LogRecord was created.
void
setThrown(Throwable thrown)
Associates this LogRecord with an exception or error.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

LogRecord

public LogRecord(Level level,
                 String message)
Constructs a LogRecord given a severity level and an unlocalized message text. In addition, the sequence number, creation time (as returned by getMillis()) and thread ID are assigned. All other properties are set to null.
Parameters:
level - the severity level, for example Level.WARNING.
message - the message text (which will be used as key for looking up the localized message text if a resource bundle has been associated).

Method Details

getLevel

public Level getLevel()
Returns the level of the LogRecord.

Applications should be aware of the possibility that the result is not necessarily one of the standard logging levels, since the logging framework allows to create custom subclasses of java.util.logging.Level. Therefore, filters should perform checks like theRecord.getLevel().intValue() == Level.INFO.intValue() instead of theRecord.getLevel() == Level.INFO.


getLoggerName

public String getLoggerName()
Returns the name of the logger where this LogRecord has originated.
Returns:
the name of the source Logger, or null if this LogRecord does not originate from a Logger.

getMessage

public String getMessage()
Returns the message for this LogRecord before any localization or parameter substitution.

A Logger will try to localize the message if a resource bundle has been associated with this LogRecord. In this case, the logger will call getMessage() and use the result as the key for looking up the localized message in the bundle. If no bundle has been associated, or if the result of getMessage() is not a valid key in the bundle, the logger will use the raw message text as returned by this method.

Returns:
the message text, or null if there is no message text.

getMillis

public long getMillis()
Returns the time when this LogRecord was created.
Returns:
the time of creation in milliseconds since the beginning of January 1, 1970.

getParameters

public Object[] getParameters()
Returns the parameters to the log message.
Returns:
the parameters to the message, or null if the message has no parameters.

getResourceBundle

public ResourceBundle getResourceBundle()
Returns the resource bundle that is used when the message of this LogRecord needs to be localized.
Returns:
the resource bundle used for localization, or null if this message does not need to be localized.

getResourceBundleName

public String getResourceBundleName()
Returns the name of the resource bundle that is used when the message of this LogRecord needs to be localized.
Returns:
the name of the resource bundle used for localization, or null if this message does not need to be localized.

getSequenceNumber

public long getSequenceNumber()
Returns the sequence number of this LogRecord.

getSourceClassName

public String getSourceClassName()
Returns the name of the class where the event being logged has had its origin. This information can be passed as parameter to some logging calls, and in certain cases, the logging framework tries to determine an approximation (which may or may not be accurate).
Returns:
the name of the class that issued the logging request, or null if this information could not be obtained.

getSourceMethodName

public String getSourceMethodName()
Returns the name of the method where the event being logged has had its origin. This information can be passed as parameter to some logging calls, and in certain cases, the logging framework tries to determine an approximation (which may or may not be accurate).
Returns:
the name of the method that issued the logging request, or null if this information could not be obtained.

getThreadID

public int getThreadID()
Returns an identifier for the thread in which this LogRecord was created. The identifier is not necessarily related to any thread identifiers used by the operating system.
Returns:
an identifier for the source thread.

getThrown

public Throwable getThrown()
Returns the Throwable associated with this LogRecord, or null if the logged event is not related to an exception or error.

setLevel

public void setLevel(Level level)
Sets the severity level of this LogRecord to a new value.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
level - the new severity level, for example Level.WARNING.

setLoggerName

public void setLoggerName(String name)
Sets the name of the logger where this LogRecord has originated.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
name - the name of the source logger, or null to indicate that this LogRecord does not originate from a Logger.

setMessage

public void setMessage(String message)
Sets the message for this LogRecord.

A Logger will try to localize the message if a resource bundle has been associated with this LogRecord. In this case, the logger will call getMessage() and use the result as the key for looking up the localized message in the bundle. If no bundle has been associated, or if the result of getMessage() is not a valid key in the bundle, the logger will use the raw message text as returned by this method.

It is possible to set the message to either an empty String or null, although this does not make the the message very helpful to human users.

Parameters:
message - the message text (which will be used as key for looking up the localized message text if a resource bundle has been associated).

setMillis

public void setMillis(long millis)
Sets the time when this LogRecord was created.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
millis - the time of creation in milliseconds since the beginning of January 1, 1970.

setParameters

public void setParameters(Object[] parameters)
Sets the parameters to the log message.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
parameters - the parameters to the message, or null to indicate that the message has no parameters.

setResourceBundle

public void setResourceBundle(ResourceBundle bundle)
Sets the resource bundle that is used when the message of this LogRecord needs to be localized.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
bundle - the resource bundle to be used, or null to indicate that this message does not need to be localized.

setResourceBundleName

public void setResourceBundleName(String name)
Sets the name of the resource bundle that is used when the message of this LogRecord needs to be localized.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
name - the name of the resource bundle to be used, or null to indicate that this message does not need to be localized.

setSequenceNumber

public void setSequenceNumber(long seqNum)
Sets the sequence number of this LogRecord to a new value.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
seqNum - the new sequence number.

setSourceClassName

public void setSourceClassName(String sourceClassName)
Sets the name of the class where the event being logged has had its origin.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
sourceClassName - the name of the class that issued the logging request, or null to indicate that this information could not be obtained.

setSourceMethodName

public void setSourceMethodName(String sourceMethodName)
Sets the name of the method where the event being logged has had its origin.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
sourceMethodName - the name of the method that issued the logging request, or null to indicate that this information could not be obtained.

setThreadID

public void setThreadID(int threadID)
Sets the identifier indicating in which thread this LogRecord was created. The identifier is not necessarily related to any thread identifiers used by the operating system.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
threadID - the identifier for the source thread.

setThrown

public void setThrown(Throwable thrown)
Associates this LogRecord with an exception or error.

As soon as a LogRecord has been handed over to the logging framework, applications should not modify it anymore. Therefore, this method should only be called on freshly constructed LogRecords.

Parameters:
thrown - the exception or error to associate with, or null if this LogRecord should be made unrelated to an exception or error.

LogRecord.java -- A class for the state associated with individual logging events Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.