📄 logrecord.java
字号:
/* LogRecord.java -- a class for the state associated with individual logging eventsCopyright (C) 2002, 2003 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe 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, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version.*/package java.util.logging;import java.util.ResourceBundle;/** * A <code>LogRecord</code> contains the state for an individual * event to be logged. * * <p>As soon as a LogRecord instance has been handed over to the * logging framework, applications should not manipulate it anymore. * * @author Sascha Brawer (brawer@acm.org) */public class LogRecord implements java.io.Serializable{ /** * The severity level of this <code>LogRecord</code>. */ private Level level; /** * The sequence number of this <code>LogRecord</code>. */ private long sequenceNumber; /** * The name of the class that issued the logging request, or * <code>null</code> if this information could not be obtained. */ private String sourceClassName; /** * The name of the method that issued the logging request, or * <code>null</code> if this information could not be obtained. */ private String sourceMethodName; /** * The message for this <code>LogRecord</code> before * any localization or formatting. */ private String message; /** * An identifier for the thread in which this <code>LogRecord</code> * was created. The identifier is not necessarily related to any * thread identifiers used by the operating system. */ private int threadID; /** * The time when this <code>LogRecord</code> was created, * in milliseconds since the beginning of January 1, 1970. */ private long millis; /** * The Throwable associated with this <code>LogRecord</code>, or * <code>null</code> if the logged event is not related to an * exception or error. */ private Throwable thrown; /** * The name of the logger where this <code>LogRecord</code> has * originated, or <code>null</code> if this <code>LogRecord</code> * does not originate from a <code>Logger</code>. */ private String loggerName; /** * The name of the resource bundle used for localizing log messages, * or <code>null</code> if no bundle has been specified. */ private String resourceBundleName; private transient Object[] parameters; private transient ResourceBundle bundle; /** * Constructs a <code>LogRecord</code> given a severity level and * an unlocalized message text. In addition, the sequence number, * creation time (as returned by <code>getMillis()</code>) and * thread ID are assigned. All other properties are set to * <code>null</code>. * * @param level the severity level, for example <code>Level.WARNING</code>. * * @param message the message text (which will be used as key * for looking up the localized message text * if a resource bundle has been associated). */ public LogRecord(Level level, String message) { this.level = level; this.message = message; this.millis = System.currentTimeMillis(); /* A subclass of java.lang.Thread could override hashCode(), * in which case the result would not be guaranteed anymore * to be unique among all threads. While System.identityHashCode * is not necessarily unique either, it at least cannot be * overridden by user code. However, is might be a good idea * to use something better for generating thread IDs. */ this.threadID = System.identityHashCode(Thread.currentThread()); sequenceNumber = allocateSeqNum(); } /** * Determined with the serialver tool of the Sun J2SE 1.4. */ static final long serialVersionUID = 5372048053134512534L; private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { in.defaultReadObject(); /* We assume that future versions will be downwards compatible, * so we can ignore the versions. */ byte majorVersion = in.readByte(); byte minorVersion = in.readByte(); int numParams = in.readInt(); if (numParams >= 0) { parameters = new Object[numParams]; for (int i = 0; i < numParams; i++) parameters[i] = in.readObject(); } } /** * @serialData The default fields, followed by a major byte version * number, followed by a minor byte version number, followed by * information about the log record parameters. If * <code>parameters</code> is <code>null</code>, the integer -1 is * written, otherwise the length of the <code>parameters</code> * array (which can be zero), followed by the result of calling * {@link Object#toString() toString()} on the parameter (or * <code>null</code> if the parameter is <code>null</code>). * * <p><strong>Specification Note:</strong> The Javadoc for the * Sun reference implementation does not specify the version * number. FIXME: Reverse-engineer the JDK and file a bug * report with Sun, asking for amendment of the specification. */ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { out.defaultWriteObject(); /* Major, minor version number: The Javadoc for J2SE1.4 does not * specify the values. */ out.writeByte(0); out.writeByte(0); if (parameters == null) out.writeInt(-1); else { out.writeInt(parameters.length); for (int i = 0; i < parameters.length; i++) { if (parameters[i] == null) out.writeObject(null); else out.writeObject(parameters[i].toString()); } } } /** * Returns the name of the logger where this <code>LogRecord</code> * has originated. * * @return the name of the source {@link Logger}, or * <code>null</code> if this <code>LogRecord</code> * does not originate from a <code>Logger</code>. */ public String getLoggerName() { return loggerName; } /** * Sets the name of the logger where this <code>LogRecord</code> * has originated. * * <p>As soon as a <code>LogRecord</code> 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. * * @param name the name of the source logger, or <code>null</code> to * indicate that this <code>LogRecord</code> does not * originate from a <code>Logger</code>. */ public void setLoggerName(String name) { loggerName = name; } /** * Returns the resource bundle that is used when the message * of this <code>LogRecord</code> needs to be localized. * * @return the resource bundle used for localization, * or <code>null</code> if this message does not need * to be localized. */ public ResourceBundle getResourceBundle() { return bundle; } /** * Sets the resource bundle that is used when the message * of this <code>LogRecord</code> needs to be localized. * * <p>As soon as a <code>LogRecord</code> 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. * * @param bundle the resource bundle to be used, or * <code>null</code> to indicate that this * message does not need to be localized. */ public void setResourceBundle(ResourceBundle bundle) { this.bundle = bundle; /* FIXME: Is there a way to infer the name * of a resource bundle from a ResourceBundle object? */ this.resourceBundleName = null; } /** * Returns the name of the resource bundle that is used when the * message of this <code>LogRecord</code> needs to be localized. * * @return the name of the resource bundle used for localization, * or <code>null</code> if this message does not need * to be localized. */ public String getResourceBundleName() { return resourceBundleName; } /** * Sets the name of the resource bundle that is used when the * message of this <code>LogRecord</code> needs to be localized. * * <p>As soon as a <code>LogRecord</code> 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. * * @param name the name of the resource bundle to be used, or * <code>null</code> to indicate that this message * does not need to be localized. */ public void setResourceBundleName(String name) { resourceBundleName = name; bundle = null; try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -