?? loggingevent.java
字號:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.log4j.spi;import org.apache.log4j.*;import org.apache.log4j.helpers.LogLog;import org.apache.log4j.helpers.Loader;import java.lang.reflect.Method;import java.io.ObjectOutputStream;import java.io.ObjectInputStream;import java.util.Hashtable;import java.util.Set;import java.util.Collections;import java.util.Map;import java.util.HashMap;// Contributors: Nelson Minar <nelson@monkey.org>// Wolf Siberski// Anders Kristensen <akristensen@dynamicsoft.com>/** The internal representation of logging events. When an affirmative decision is made to log then a <code>LoggingEvent</code> instance is created. This instance is passed around to the different log4j components. <p>This class is of concern to those wishing to extend log4j. @author Ceki Gülcü @author James P. Cakalic @since 0.8.2 */public class LoggingEvent implements java.io.Serializable { private static long startTime = System.currentTimeMillis(); /** Fully qualified name of the calling category class. */ transient public final String fqnOfCategoryClass; /** * The category of the logging event. This field is not serialized * for performance reasons. * * <p>It is set by the LoggingEvent constructor or set by a remote * entity after deserialization. * * @deprecated This field will be marked as private or be completely * removed in future releases. Please do not use it. * */ transient private Category logger; /** * <p>The category (logger) name. * * @deprecated This field will be marked as private in future * releases. Please do not access it directly. Use the {@link * #getLoggerName} method instead. * */ final public String categoryName; /** * Level of logging event. Level cannot be serializable because it * is a flyweight. Due to its special seralization it cannot be * declared final either. * * <p> This field should not be accessed directly. You shoud use the * {@link #getLevel} method instead. * * @deprecated This field will be marked as private in future * releases. Please do not access it directly. Use the {@link * #getLevel} method instead. * */ transient public Priority level; /** The nested diagnostic context (NDC) of logging event. */ private String ndc; /** The mapped diagnostic context (MDC) of logging event. */ private Hashtable mdcCopy; /** Have we tried to do an NDC lookup? If we did, there is no need * to do it again. Note that its value is always false when * serialized. Thus, a receiving SocketNode will never use it's own * (incorrect) NDC. See also writeObject method. */ private boolean ndcLookupRequired = true; /** Have we tried to do an MDC lookup? If we did, there is no need * to do it again. Note that its value is always false when * serialized. See also the getMDC and getMDCCopy methods. */ private boolean mdcCopyLookupRequired = true; /** The application supplied message of logging event. */ transient private Object message; /** The application supplied message rendered through the log4j objet rendering mechanism.*/ private String renderedMessage; /** The name of thread in which this logging event was generated. */ private String threadName; /** This variable contains information about this event's throwable */ private ThrowableInformation throwableInfo; /** The number of milliseconds elapsed from 1/1/1970 until logging event was created. */ public final long timeStamp; /** Location information for the caller. */ private LocationInfo locationInfo; // Serialization static final long serialVersionUID = -868428216207166145L; static final Integer[] PARAM_ARRAY = new Integer[1]; static final String TO_LEVEL = "toLevel"; static final Class[] TO_LEVEL_PARAMS = new Class[] {int.class}; static final Hashtable methodCache = new Hashtable(3); // use a tiny table /** Instantiate a LoggingEvent from the supplied parameters. <p>Except {@link #timeStamp} all the other fields of <code>LoggingEvent</code> are filled when actually needed. <p> @param logger The logger generating this event. @param level The level of this event. @param message The message of this event. @param throwable The throwable of this event. */ public LoggingEvent(String fqnOfCategoryClass, Category logger, Priority level, Object message, Throwable throwable) { this.fqnOfCategoryClass = fqnOfCategoryClass; this.logger = logger; this.categoryName = logger.getName(); this.level = level; this.message = message; if(throwable != null) { this.throwableInfo = new ThrowableInformation(throwable); } timeStamp = System.currentTimeMillis(); } /** Instantiate a LoggingEvent from the supplied parameters. <p>Except {@link #timeStamp} all the other fields of <code>LoggingEvent</code> are filled when actually needed. <p> @param logger The logger generating this event. @param timeStamp the timestamp of this logging event @param level The level of this event. @param message The message of this event. @param throwable The throwable of this event. */ public LoggingEvent(String fqnOfCategoryClass, Category logger, long timeStamp, Priority level, Object message, Throwable throwable) { this.fqnOfCategoryClass = fqnOfCategoryClass; this.logger = logger; this.categoryName = logger.getName(); this.level = level; this.message = message; if(throwable != null) { this.throwableInfo = new ThrowableInformation(throwable); } this.timeStamp = timeStamp; } /** Create new instance. @since 1.2.15 @param fqnOfCategoryClass Fully qualified class name of Logger implementation. @param logger The logger generating this event. @param timeStamp the timestamp of this logging event @param level The level of this event. @param message The message of this event. @param threadName thread name @param throwable The throwable of this event. @param ndc Nested diagnostic context @param info Location info @param properties MDC properties */ public LoggingEvent(final String fqnOfCategoryClass, final Category logger, final long timeStamp, final Level level, final Object message, final String threadName, final ThrowableInformation throwable, final String ndc, final LocationInfo info, final java.util.Map properties) { super(); this.fqnOfCategoryClass = fqnOfCategoryClass; this.logger = logger; if (logger != null) { categoryName = logger.getName(); } else { categoryName = null; } this.level = level; this.message = message; if(throwable != null) { this.throwableInfo = throwable; } this.timeStamp = timeStamp; this.threadName = threadName; ndcLookupRequired = false; this.ndc = ndc; this.locationInfo = info; mdcCopyLookupRequired = false; if (properties != null) { mdcCopy = new java.util.Hashtable(properties); } } /** Set the location information for this logging event. The collected information is cached for future use. */ public LocationInfo getLocationInformation() { if(locationInfo == null) { locationInfo = new LocationInfo(new Throwable(), fqnOfCategoryClass); } return locationInfo; } /** * Return the level of this event. Use this form instead of directly * accessing the <code>level</code> field. */ public Level getLevel() { return (Level) level; } /** * Return the name of the logger. Use this form instead of directly * accessing the <code>categoryName</code> field. */ public String getLoggerName() { return categoryName; } /** * Gets the logger of the event. * Use should be restricted to cloning events. * @since 1.2.15 */ public Category getLogger() { return logger; } /** Return the message for this logging event. <p>Before serialization, the returned object is the message passed by the user to generate the logging event. After serialization, the returned value equals the String form of the message possibly after object rendering. @since 1.1 */ public Object getMessage() { if(message != null) { return message; } else { return getRenderedMessage(); } } /** * This method returns the NDC for this event. It will return the * correct content even if the event was generated in a different * thread or even on a different machine. The {@link NDC#get} method * should <em>never</em> be called directly. */ public String getNDC() { if(ndcLookupRequired) { ndcLookupRequired = false; ndc = NDC.get();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -