29869edc191c51904b3021954c165f4a2bee63e5
[jalview.git] / srcjar_unused / org / apache / log4j / helpers / LogLog.java
1 /*
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  */
17
18 package org.apache.log4j.helpers;
19
20 /**
21    This class used to output log statements from within the log4j package.
22
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.
27
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
31    the string "log4j: ".
32    
33    @since 0.8.2
34    @author Ceki G&uuml;lc&uuml;
35 */
36 public class LogLog {
37
38   /**
39      Defining this value makes log4j print log4j-internal debug
40      statements to <code>System.out</code>.
41      
42     <p> The value of this string is <b>log4j.debug</b>.
43     
44     <p>Note that the search for all option names is case sensitive.  */
45   public static final String DEBUG_KEY="log4j.debug";
46
47  
48   /**
49      Defining this value makes log4j components print log4j-internal
50      debug statements to <code>System.out</code>.
51      
52     <p> The value of this string is <b>log4j.configDebug</b>.
53     
54     <p>Note that the search for all option names is case sensitive.  
55
56     @deprecated Use {@link #DEBUG_KEY} instead.
57   */
58   public static final String CONFIG_DEBUG_KEY="log4j.configDebug";
59
60   protected static boolean debugEnabled = false;  
61
62   /**
63      In quietMode not even errors generate any output.
64    */
65   private static boolean quietMode = false;
66
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 ";
70
71   static {
72     String key = OptionConverter.getSystemProperty(DEBUG_KEY, null);
73
74     if(key == null) {
75       key = OptionConverter.getSystemProperty(CONFIG_DEBUG_KEY, null);
76     }
77
78     if(key != null) { 
79       debugEnabled = OptionConverter.toBoolean(key, true);
80     }
81   }
82
83   /**
84      Allows to enable/disable log4j internal logging.
85    */
86   static
87   public
88   void setInternalDebugging(boolean enabled) {
89     debugEnabled = enabled;
90   }
91
92   /**
93      This method is used to output log4j internal debug
94      statements. Output goes to <code>System.out</code>.
95   */
96   public
97   static
98   void debug(String msg) {
99     if(debugEnabled && !quietMode) {
100       System.out.println(PREFIX+msg);
101     }
102   }
103
104   /**
105      This method is used to output log4j internal debug
106      statements. Output goes to <code>System.out</code>.
107   */
108   public
109   static
110   void debug(String msg, Throwable t) {
111     if(debugEnabled && !quietMode) {
112       System.out.println(PREFIX+msg);
113       if(t != null) {
114         t.printStackTrace(System.out);
115     }
116     }
117   }
118   
119
120   /**
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>.
124   */
125   public
126   static
127   void error(String msg) {
128     if(quietMode) {
129         return;
130     }
131     System.err.println(ERR_PREFIX+msg);
132   }  
133
134   /**
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>.  
138   */
139   public
140   static
141   void error(String msg, Throwable t) {
142     if(quietMode) {
143         return;
144     }
145
146     System.err.println(ERR_PREFIX+msg);
147     if(t != null) {
148       t.printStackTrace();
149     }
150   }  
151
152   /**
153      In quite mode no LogLog generates strictly no output, not even
154      for errors. 
155
156      @param quietMode A true for not
157   */
158   public
159   static
160   void setQuietMode(boolean quietMode) {
161     LogLog.quietMode = quietMode;
162   }
163
164   /**
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>.  */
168   public
169   static
170   void warn(String msg) {
171     if(quietMode) {
172         return;
173     }
174
175     System.err.println(WARN_PREFIX+msg);
176   }  
177
178   /**
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>.  */
182   public
183   static
184   void warn(String msg, Throwable t) {
185     if(quietMode) {
186         return;
187     }
188
189     System.err.println(WARN_PREFIX+msg);
190     if(t != null) {
191       t.printStackTrace();
192     }
193   }  
194 }