1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.mortbay.log;
16 import java.lang.reflect.Method;
17
18 import org.mortbay.util.Loader;
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public class Log
33 {
34 private static final String[] __nestedEx =
35 {"getTargetException","getTargetError","getException","getRootCause"};
36
37 private static final Class[] __noArgs=new Class[0];
38 public final static String EXCEPTION= "EXCEPTION ";
39 public final static String IGNORED= "IGNORED";
40 public final static String IGNORED_FMT= "IGNORED: {}";
41 public final static String NOT_IMPLEMENTED= "NOT IMPLEMENTED ";
42
43 private static String logClass=System.getProperty("org.mortbay.log.class","org.mortbay.log.Slf4jLog");
44 private static boolean verbose = System.getProperty("VERBOSE",null)!=null;
45 private static boolean ignored = System.getProperty("IGNORED",null)!=null;
46 private static Logger log;
47
48 static
49 {
50 Class log_class=null;
51 try
52 {
53 log_class=Loader.loadClass(Log.class, logClass);
54 log=(Logger) log_class.newInstance();
55 }
56 catch(Exception e)
57 {
58 log_class=StdErrLog.class;
59 log=new StdErrLog();
60 if(verbose)
61 e.printStackTrace();
62 }
63
64 log.info("Logging to {} via {}",log,log_class.getName());
65 }
66
67 public static void setLog(Logger log)
68 {
69 Log.log=log;
70 }
71
72 public static Logger getLog()
73 {
74 return log;
75 }
76
77
78 public static void debug(Throwable th)
79 {
80 if (log==null || !isDebugEnabled())
81 return;
82 log.debug(EXCEPTION,th);
83 unwind(th);
84 }
85
86 public static void debug(String msg)
87 {
88 if (log==null)
89 return;
90 log.debug(msg,null,null);
91 }
92
93 public static void debug(String msg,Object arg)
94 {
95 if (log==null)
96 return;
97 log.debug(msg,arg,null);
98 }
99
100 public static void debug(String msg,Object arg0, Object arg1)
101 {
102 if (log==null)
103 return;
104 log.debug(msg,arg0,arg1);
105 }
106
107
108
109
110
111
112 public static void ignore(Throwable th)
113 {
114 if (log==null)
115 return;
116 if (ignored)
117 {
118 log.warn(IGNORED,th);
119 unwind(th);
120 }
121 else if (verbose)
122 {
123 log.debug(IGNORED,th);
124 unwind(th);
125 }
126 }
127
128 public static void info(String msg)
129 {
130 if (log==null)
131 return;
132 log.info(msg,null,null);
133 }
134
135 public static void info(String msg,Object arg)
136 {
137 if (log==null)
138 return;
139 log.info(msg,arg,null);
140 }
141
142 public static void info(String msg,Object arg0, Object arg1)
143 {
144 if (log==null)
145 return;
146 log.info(msg,arg0,arg1);
147 }
148
149 public static boolean isDebugEnabled()
150 {
151 if (log==null)
152 return false;
153 return log.isDebugEnabled();
154 }
155
156 public static void warn(String msg)
157 {
158 if (log==null)
159 return;
160 log.warn(msg,null,null);
161 }
162
163 public static void warn(String msg,Object arg)
164 {
165 if (log==null)
166 return;
167 log.warn(msg,arg,null);
168 }
169
170 public static void warn(String msg,Object arg0, Object arg1)
171 {
172 if (log==null)
173 return;
174 log.warn(msg,arg0,arg1);
175 }
176
177 public static void warn(String msg, Throwable th)
178 {
179 if (log==null)
180 return;
181 log.warn(msg,th);
182 unwind(th);
183 }
184
185 public static void warn(Throwable th)
186 {
187 if (log==null)
188 return;
189 log.warn(EXCEPTION,th);
190 unwind(th);
191 }
192
193
194
195
196 public static Logger getLogger(String name)
197 {
198 if (log==null)
199 return log;
200 if (name==null)
201 return log;
202 return log.getLogger(name);
203 }
204
205 private static void unwind(Throwable th)
206 {
207 if (th==null)
208 return;
209 for (int i=0;i<__nestedEx.length;i++)
210 {
211 try
212 {
213 Method get_target = th.getClass().getMethod(__nestedEx[i],__noArgs);
214 Throwable th2=(Throwable)get_target.invoke(th,(Object[])null);
215 if (th2!=null && th2!=th)
216 warn("Nested in "+th+":",th2);
217 }
218 catch(Exception ignore){}
219 }
220 }
221
222
223 }
224