2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.log4j;
20 import org.apache.log4j.spi.LoggerFactory;
24 This is the central class in the log4j package. Most logging
25 operations, except configuration, are done through this class.
29 @author Ceki Gülcü */
30 public class Logger extends Category {
33 The fully qualified name of the Logger class. See also the
35 private static final String FQCN = Logger.class.getName();
44 * Retrieve a logger named according to the value of the
45 * <code>name</code> parameter. If the named logger already exists,
46 * then the existing instance will be returned. Otherwise, a new
47 * instance is created.
49 * <p>By default, loggers do not have a set level but inherit it
50 * from their neareast ancestor with a set level. This is one of the
51 * central features of log4j.
53 * @param name The name of the logger to retrieve.
57 Logger getLogger(String name) {
58 return LogManager.getLogger(name);
62 * Shorthand for <code>getLogger(clazz.getName())</code>.
64 * @param clazz The name of <code>clazz</code> will be used as the
65 * name of the logger to retrieve. See {@link #getLogger(String)}
66 * for more detailed information.
70 Logger getLogger(Class clazz) {
71 return LogManager.getLogger(clazz.getName());
76 * Return the root logger for the current logger repository.
78 * The {@link #getName Logger.getName()} method for the root logger always returns
79 * string value: "root". However, calling
80 * <code>Logger.getLogger("root")</code> does not retrieve the root
81 * logger but a logger just under root named "root".
83 * In other words, calling this method is the only way to retrieve the
88 Logger getRootLogger() {
89 return LogManager.getRootLogger();
93 Like {@link #getLogger(String)} except that the type of logger
94 instantiated depends on the type returned by the {@link
95 LoggerFactory#makeNewLoggerInstance} method of the
96 <code>factory</code> parameter.
98 <p>This method is intended to be used by sub-classes.
100 @param name The name of the logger to retrieve.
102 @param factory A {@link LoggerFactory} implementation that will
103 actually create a new Instance.
108 Logger getLogger(String name, LoggerFactory factory) {
109 return LogManager.getLogger(name, factory);
113 * Log a message object with the {@link org.apache.log4j.Level#TRACE TRACE} level.
115 * @param message the message object to log.
116 * @see #debug(Object) for an explanation of the logic applied.
119 public void trace(Object message) {
120 if (repository.isDisabled(Level.TRACE_INT)) {
124 if (Level.TRACE.isGreaterOrEqual(this.getEffectiveLevel())) {
125 forcedLog(FQCN, Level.TRACE, message, null);
130 * Log a message object with the <code>TRACE</code> level including the
131 * stack trace of the {@link Throwable}<code>t</code> passed as parameter.
134 * See {@link #debug(Object)} form for more detailed information.
137 * @param message the message object to log.
138 * @param t the exception to log, including its stack trace.
141 public void trace(Object message, Throwable t) {
142 if (repository.isDisabled(Level.TRACE_INT)) {
146 if (Level.TRACE.isGreaterOrEqual(this.getEffectiveLevel())) {
147 forcedLog(FQCN, Level.TRACE, message, t);
152 * Check whether this category is enabled for the TRACE Level.
155 * @return boolean - <code>true</code> if this category is enabled for level
156 * TRACE, <code>false</code> otherwise.
158 public boolean isTraceEnabled() {
159 if (repository.isDisabled(Level.TRACE_INT)) {
163 return Level.TRACE.isGreaterOrEqual(this.getEffectiveLevel());