FileDocCategorySizeDatePackage
LogRecord.javaAPI DocAndroid 1.5 API15685Wed May 06 22:41:04 BST 2009java.util.logging

LogRecord

public class LogRecord extends Object implements Serializable
A {@code LogRecord} object represents a logging request. It is passed between the logging framework and individual logging handlers. Client applications should not modify a {@code LogRecord} object that has been passed into the logging framework.

The {@code LogRecord} class will infer the source method name and source class name the first time they are accessed if the client application didn't specify them explicitly. This automatic inference is based on the analysis of the call stack and is not guaranteed to be precise. Client applications should force the initialization of these two fields by calling {@code getSourceClassName} or {@code getSourceMethodName} if they expect to use them after passing the {@code LogRecord} object to another thread or transmitting it over RMI.

since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private static final int
MAJOR
private static final int
MINOR
private static long
currentSequenceNumber
private static ThreadLocal
currentThreadId
private static int
initThreadId
private Level
level
The logging level.
private long
sequenceNumber
The sequence number.
private String
sourceClassName
The name of the class that issued the logging call.
private String
sourceMethodName
The name of the method that issued the logging call.
private String
message
The original message text.
private int
threadID
The ID of the thread that issued the logging call.
private long
millis
The time that the event occurred, in milliseconds since 1970.
private Throwable
thrown
The associated {@code Throwable} object if any.
private String
loggerName
The name of the source logger.
private String
resourceBundleName
The name of the resource bundle used to localize the log message.
private transient ResourceBundle
resourceBundle
private transient Object[]
parameters
private transient boolean
sourceInited
Constructors Summary
public LogRecord(Level level, String msg)
Constructs a {@code LogRecord} object using the supplied the logging level and message. The millis property is set to the current time. The sequence property is set to a new unique value, allocated in increasing order within the virtual machine. The thread ID is set to a unique value for the current thread. All other properties are set to {@code null}.

param
level the logging level, may not be {@code null}.
param
msg the raw message.
throws
NullPointerException if {@code level} is {@code null}.
since
Android 1.0


                                                                                                                                   
         
        if (null == level) {
            // logging.4=The 'level' parameter is null.
            throw new NullPointerException(Messages.getString("logging.4")); //$NON-NLS-1$
        }
        this.level = level;
        this.message = msg;
        this.millis = System.currentTimeMillis();

        synchronized (LogRecord.class) {
            this.sequenceNumber = currentSequenceNumber++;
            Integer id = currentThreadId.get();
            if (null == id) {
                this.threadID = initThreadId;
                currentThreadId.set(Integer.valueOf(initThreadId++));
            } else {
                this.threadID = id.intValue();
            }
        }

        this.sourceClassName = null;
        this.sourceMethodName = null;
        this.loggerName = null;
        this.parameters = null;
        this.resourceBundle = null;
        this.resourceBundleName = null;
        this.thrown = null;
    
Methods Summary
public java.util.logging.LevelgetLevel()
Gets the logging level.

return
the logging level.
since
Android 1.0

        return level;
    
public java.lang.StringgetLoggerName()
Gets the name of the logger.

return
the logger name.
since
Android 1.0

        return loggerName;
    
public java.lang.StringgetMessage()
Gets the raw message.

return
the raw message, may be {@code null}.
since
Android 1.0

        return message;
    
public longgetMillis()
Gets the time when this event occurred, in milliseconds since 1970.

return
the time when this event occurred, in milliseconds since 1970.
since
Android 1.0

        return millis;
    
public java.lang.Object[]getParameters()
Gets the parameters.

return
the array of parameters or {@code null} if there are no parameters.
since
Android 1.0

        return parameters;
    
public java.util.ResourceBundlegetResourceBundle()
Gets the resource bundle used to localize the raw message during formatting.

return
the associated resource bundle, {@code null} if none is available or the message is not localizable.
since
Android 1.0

        return resourceBundle;
    
public java.lang.StringgetResourceBundleName()
Gets the name of the resource bundle.

return
the name of the resource bundle, {@code null} if none is available or the message is not localizable.
since
Android 1.0

        return resourceBundleName;
    
public longgetSequenceNumber()
Gets the sequence number.

return
the sequence number.
since
Android 1.0

        return sequenceNumber;
    
public java.lang.StringgetSourceClassName()
Gets the name of the class that is the source of this log record. This information can be changed, may be {@code null} and is untrusted.

return
the name of the source class of this log record (possiblity {@code null})
since
Android 1.0

        initSource();
        return sourceClassName;
    
public java.lang.StringgetSourceMethodName()
Gets the name of the method that is the source of this log record.

return
the name of the source method of this log record.
since
Android 1.0

        initSource();
        return sourceMethodName;
    
public intgetThreadID()
Gets a unique ID of the thread originating the log record. Every thread becomes a different ID.

Notice : the ID doesn't necessary map the OS thread ID

return
the ID of the thread originating this log record.
since
Android 1.0

        return threadID;
    
public java.lang.ThrowablegetThrown()
Gets the {@code Throwable} object associated with this log record.

return
the {@code Throwable} object associated with this log record.
since
Android 1.0

        return thrown;
    
private voidinitSource()

        if (!sourceInited) {
            StackTraceElement[] elements = (new Throwable()).getStackTrace();
            int i = 0;
            String current = null;
            FINDLOG: for (; i < elements.length; i++) {
                current = elements[i].getClassName();
                if (current.equals(Logger.class.getName())) {
                    break FINDLOG;
                }
            }
            while(++i<elements.length && elements[i].getClassName().equals(current)) {
                // do nothing
            }
            if (i < elements.length) {
                this.sourceClassName = elements[i].getClassName();
                this.sourceMethodName = elements[i].getMethodName();
            }
            sourceInited = true;
        }
    
private voidreadObject(java.io.ObjectInputStream in)

        in.defaultReadObject();
        byte major = in.readByte();
        byte minor = in.readByte();
        //only check MAJOR version
        if (major != MAJOR) {
            // logging.5=Different version - {0}.{1}
            throw new IOException(Messages.getString("logging.5", major, minor)); //$NON-NLS-1$ 
        }
        
        int length = in.readInt();
        if (length >= 0) {
            parameters = new Object[length];
            for (int i = 0; i < parameters.length; i++) {
                parameters[i] = in.readObject();
            }
        }
        if (null != resourceBundleName) {
            try {
                resourceBundle = Logger.loadResourceBundle(resourceBundleName);
            } catch (MissingResourceException e) {
                // Cannot find the specified resource bundle
                resourceBundle = null;
            }
        }
    
public voidsetLevel(java.util.logging.Level level)
Sets the logging level.

param
level the level to set.
throws
NullPointerException if {@code level} is {@code null}.
since
Android 1.0

        if (null == level) {
            // logging.4=The 'level' parameter is null.
            throw new NullPointerException(Messages.getString("logging.4")); //$NON-NLS-1$
        }
        this.level = level;
    
public voidsetLoggerName(java.lang.String loggerName)
Sets the name of the logger.

param
loggerName the logger name to set.
since
Android 1.0

        this.loggerName = loggerName;
    
public voidsetMessage(java.lang.String message)
Sets the raw message. When this record is formatted by a logger that has a localization resource bundle that contains an entry for {@code message}, then the raw message is replaced with its localized version.

param
message the raw message to set, may be {@code null}.
since
Android 1.0

        this.message = message;
    
public voidsetMillis(long millis)
Sets the time when this event occurred, in milliseconds since 1970.

param
millis the time when this event occurred, in milliseconds since 1970.
since
Android 1.0

        this.millis = millis;
    
public voidsetParameters(java.lang.Object[] parameters)
Sets the parameters.

param
parameters the array of parameters to set, may be {@code null}.
since
Android 1.0

        this.parameters = parameters;
    
public voidsetResourceBundle(java.util.ResourceBundle resourceBundle)
Sets the resource bundle.

param
resourceBundle the resource bundle to set, may be {@code null}.
since
Android 1.0

        this.resourceBundle = resourceBundle;
    
public voidsetResourceBundleName(java.lang.String resourceBundleName)
Sets the name of the resource bundle.

param
resourceBundleName the name of the resource bundle to set.
since
Android 1.0

        this.resourceBundleName = resourceBundleName;
    
public voidsetSequenceNumber(long sequenceNumber)
Sets the sequence number. It is usually not necessary to call this method to change the sequence number because the number is allocated when this instance is constructed.

param
sequenceNumber the sequence number to set.
since
Android 1.0

        this.sequenceNumber = sequenceNumber;
    
public voidsetSourceClassName(java.lang.String sourceClassName)
Sets the name of the class that is the source of this log record.

param
sourceClassName the name of the source class of this log record, may be {@code null}.
since
Android 1.0

        sourceInited = true;
        this.sourceClassName = sourceClassName;
    
public voidsetSourceMethodName(java.lang.String sourceMethodName)
Sets the name of the method that is the source of this log record.

param
sourceMethodName the name of the source method of this log record, may be {@code null}.
since
Android 1.0

        sourceInited = true;
        this.sourceMethodName = sourceMethodName;
    
public voidsetThreadID(int threadID)
Sets the ID of the thread originating this log record.

param
threadID the new ID of the thread originating this log record.
since
Android 1.0

        this.threadID = threadID;
    
public voidsetThrown(java.lang.Throwable thrown)
Sets the {@code Throwable} object associated with this log record.

param
thrown the new {@code Throwable} object to associate with this log record.
since
Android 1.0

        this.thrown = thrown;
    
private voidwriteObject(java.io.ObjectOutputStream out)

        out.defaultWriteObject();
        out.writeByte(MAJOR);
        out.writeByte(MINOR);
        if (null == parameters) {
            out.writeInt(-1);
        } else {
            out.writeInt(parameters.length);
            for (Object element : parameters) {
                out.writeObject(null == element ? null : element.toString());
            }
        }