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.helpers;
21 This class used to output log statements from within the log4j package.
23 <p>Log4j components cannot make log4j logging calls. However, it is
24 sometimes useful for the user to learn about what log4j is
25 doing. You can enable log4j internal logging by defining the
26 <b>log4j.configDebug</b> variable.
28 <p>All log4j internal debug calls go to <code>System.out</code>
29 where as internal error messages are sent to
30 <code>System.err</code>. All internal messages are prepended with
34 @author Ceki Gülcü
39 Defining this value makes log4j print log4j-internal debug
40 statements to <code>System.out</code>.
42 <p> The value of this string is <b>log4j.debug</b>.
44 <p>Note that the search for all option names is case sensitive. */
45 public static final String DEBUG_KEY="log4j.debug";
49 Defining this value makes log4j components print log4j-internal
50 debug statements to <code>System.out</code>.
52 <p> The value of this string is <b>log4j.configDebug</b>.
54 <p>Note that the search for all option names is case sensitive.
56 @deprecated Use {@link #DEBUG_KEY} instead.
58 public static final String CONFIG_DEBUG_KEY="log4j.configDebug";
60 protected static boolean debugEnabled = false;
63 In quietMode not even errors generate any output.
65 private static boolean quietMode = false;
67 private static final String PREFIX = "log4j: ";
68 private static final String ERR_PREFIX = "log4j:ERROR ";
69 private static final String WARN_PREFIX = "log4j:WARN ";
72 String key = OptionConverter.getSystemProperty(DEBUG_KEY, null);
75 key = OptionConverter.getSystemProperty(CONFIG_DEBUG_KEY, null);
79 debugEnabled = OptionConverter.toBoolean(key, true);
84 Allows to enable/disable log4j internal logging.
88 void setInternalDebugging(boolean enabled) {
89 debugEnabled = enabled;
93 This method is used to output log4j internal debug
94 statements. Output goes to <code>System.out</code>.
98 void debug(String msg) {
99 if(debugEnabled && !quietMode) {
100 System.out.println(PREFIX+msg);
105 This method is used to output log4j internal debug
106 statements. Output goes to <code>System.out</code>.
110 void debug(String msg, Throwable t) {
111 if(debugEnabled && !quietMode) {
112 System.out.println(PREFIX+msg);
114 t.printStackTrace(System.out);
121 This method is used to output log4j internal error
122 statements. There is no way to disable error statements.
123 Output goes to <code>System.err</code>.
127 void error(String msg) {
131 System.err.println(ERR_PREFIX+msg);
135 This method is used to output log4j internal error
136 statements. There is no way to disable error statements.
137 Output goes to <code>System.err</code>.
141 void error(String msg, Throwable t) {
146 System.err.println(ERR_PREFIX+msg);
153 In quite mode no LogLog generates strictly no output, not even
156 @param quietMode A true for not
160 void setQuietMode(boolean quietMode) {
161 LogLog.quietMode = quietMode;
165 This method is used to output log4j internal warning
166 statements. There is no way to disable warning statements.
167 Output goes to <code>System.err</code>. */
170 void warn(String msg) {
175 System.err.println(WARN_PREFIX+msg);
179 This method is used to output log4j internal warnings. There is
180 no way to disable warning statements. Output goes to
181 <code>System.err</code>. */
184 void warn(String msg, Throwable t) {
189 System.err.println(WARN_PREFIX+msg);