KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > el > Logger


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 1999 The Apache Software Foundation. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if
20  * any, must include the following acknowlegement:
21  * "This product includes software developed by the
22  * Apache Software Foundation (http://www.apache.org/)."
23  * Alternately, this acknowlegement may appear in the software itself,
24  * if and wherever such third-party acknowlegements normally appear.
25  *
26  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
27  * Foundation" must not be used to endorse or promote products derived
28  * from this software without prior written permission. For written
29  * permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache"
32  * nor may "Apache" appear in their names without prior written
33  * permission of the Apache Group.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation. For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  *
54  */

55
56 package org.apache.commons.el;
57
58 import java.io.PrintStream JavaDoc;
59 import java.text.MessageFormat JavaDoc;
60 import javax.servlet.jsp.el.ELException JavaDoc;
61
62 /**
63  *
64  * <p>The evaluator may pass an instance of this class to operators
65  * and expressions during evaluation. They should use this to log any
66  * warning or error messages that might come up. This allows all of
67  * our logging policies to be concentrated in one class.
68  *
69  * <p>Errors are conditions that are severe enough to abort operation.
70  * Warnings are conditions through which the operation may continue,
71  * but which should be reported to the developer.
72  *
73  * @author Nathan Abramson - Art Technology Group
74  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: luehe $
75  **/

76
77 public class Logger
78 {
79   //-------------------------------------
80
// Member variables
81
//-------------------------------------
82

83   PrintStream JavaDoc mOut;
84
85   //-------------------------------------
86
/**
87    *
88    * Constructor
89    *
90    * @param pOut the PrintStream to which warnings should be printed
91    **/

92   public Logger (PrintStream JavaDoc pOut)
93   {
94     mOut = pOut;
95   }
96
97   //-------------------------------------
98
/**
99    *
100    * Returns true if the application should even bother to try logging
101    * a warning.
102    **/

103   public boolean isLoggingWarning ()
104   {
105     return false;
106   }
107
108   //-------------------------------------
109
/**
110    *
111    * Logs a warning
112    **/

113   public void logWarning (String JavaDoc pMessage,
114               Throwable JavaDoc pRootCause)
115     throws ELException JavaDoc
116   {
117     if (isLoggingWarning ()) {
118       if (pMessage == null) {
119     System.out.println (pRootCause);
120       }
121       else if (pRootCause == null) {
122     System.out.println (pMessage);
123       }
124       else {
125     System.out.println (pMessage + ": " + pRootCause);
126       }
127     }
128   }
129
130   //-------------------------------------
131
/**
132    *
133    * Logs a warning
134    **/

135   public void logWarning (String JavaDoc pTemplate)
136     throws ELException JavaDoc
137   {
138     if (isLoggingWarning ()) {
139       logWarning (pTemplate, null);
140     }
141   }
142
143   //-------------------------------------
144
/**
145    *
146    * Logs a warning
147    **/

148   public void logWarning (Throwable JavaDoc pRootCause)
149     throws ELException JavaDoc
150   {
151     if (isLoggingWarning ()) {
152       logWarning (null, pRootCause);
153     }
154   }
155
156   //-------------------------------------
157
/**
158    *
159    * Logs a warning
160    **/

161   public void logWarning (String JavaDoc pTemplate,
162               Object JavaDoc pArg0)
163     throws ELException JavaDoc
164   {
165     if (isLoggingWarning ()) {
166       logWarning
167     (MessageFormat.format
168      (pTemplate,
169       new Object JavaDoc [] {
170         "" + pArg0,
171       }));
172     }
173   }
174
175   //-------------------------------------
176
/**
177    *
178    * Logs a warning
179    **/

180   public void logWarning (String JavaDoc pTemplate,
181               Throwable JavaDoc pRootCause,
182               Object JavaDoc pArg0)
183     throws ELException JavaDoc
184   {
185     if (isLoggingWarning ()) {
186       logWarning
187     (MessageFormat.format
188      (pTemplate,
189       new Object JavaDoc [] {
190         "" + pArg0,
191       }),
192      pRootCause);
193     }
194   }
195
196   //-------------------------------------
197
/**
198    *
199    * Logs a warning
200    **/

201   public void logWarning (String JavaDoc pTemplate,
202               Object JavaDoc pArg0,
203               Object JavaDoc pArg1)
204     throws ELException JavaDoc
205   {
206     if (isLoggingWarning ()) {
207       logWarning
208     (MessageFormat.format
209      (pTemplate,
210       new Object JavaDoc [] {
211         "" + pArg0,
212         "" + pArg1,
213       }));
214     }
215   }
216
217   //-------------------------------------
218
/**
219    *
220    * Logs a warning
221    **/

222   public void logWarning (String JavaDoc pTemplate,
223               Throwable JavaDoc pRootCause,
224               Object JavaDoc pArg0,
225               Object JavaDoc pArg1)
226     throws ELException JavaDoc
227   {
228     if (isLoggingWarning ()) {
229       logWarning
230     (MessageFormat.format
231      (pTemplate,
232       new Object JavaDoc [] {
233         "" + pArg0,
234         "" + pArg1,
235       }),
236      pRootCause);
237     }
238   }
239
240   //-------------------------------------
241
/**
242    *
243    * Logs a warning
244    **/

245   public void logWarning (String JavaDoc pTemplate,
246               Object JavaDoc pArg0,
247               Object JavaDoc pArg1,
248               Object JavaDoc pArg2)
249     throws ELException JavaDoc
250   {
251     if (isLoggingWarning ()) {
252       logWarning
253     (MessageFormat.format
254      (pTemplate,
255       new Object JavaDoc [] {
256         "" + pArg0,
257         "" + pArg1,
258         "" + pArg2,
259       }));
260     }
261   }
262
263   //-------------------------------------
264
/**
265    *
266    * Logs a warning
267    **/

268   public void logWarning (String JavaDoc pTemplate,
269               Throwable JavaDoc pRootCause,
270               Object JavaDoc pArg0,
271               Object JavaDoc pArg1,
272               Object JavaDoc pArg2)
273     throws ELException JavaDoc
274   {
275     if (isLoggingWarning ()) {
276       logWarning
277     (MessageFormat.format
278      (pTemplate,
279       new Object JavaDoc [] {
280         "" + pArg0,
281         "" + pArg1,
282         "" + pArg2,
283       }),
284      pRootCause);
285     }
286   }
287
288   //-------------------------------------
289
/**
290    *
291    * Logs a warning
292    **/

293   public void logWarning (String JavaDoc pTemplate,
294               Object JavaDoc pArg0,
295               Object JavaDoc pArg1,
296               Object JavaDoc pArg2,
297               Object JavaDoc pArg3)
298     throws ELException JavaDoc
299   {
300     if (isLoggingWarning ()) {
301       logWarning
302     (MessageFormat.format
303      (pTemplate,
304       new Object JavaDoc [] {
305         "" + pArg0,
306         "" + pArg1,
307         "" + pArg2,
308         "" + pArg3,
309       }));
310     }
311   }
312
313   //-------------------------------------
314
/**
315    *
316    * Logs a warning
317    **/

318   public void logWarning (String JavaDoc pTemplate,
319               Throwable JavaDoc pRootCause,
320               Object JavaDoc pArg0,
321               Object JavaDoc pArg1,
322               Object JavaDoc pArg2,
323               Object JavaDoc pArg3)
324     throws ELException JavaDoc
325   {
326     if (isLoggingWarning ()) {
327       logWarning
328     (MessageFormat.format
329      (pTemplate,
330       new Object JavaDoc [] {
331         "" + pArg0,
332         "" + pArg1,
333         "" + pArg2,
334         "" + pArg3,
335       }),
336      pRootCause);
337     }
338   }
339
340   //-------------------------------------
341
/**
342    *
343    * Logs a warning
344    **/

345   public void logWarning (String JavaDoc pTemplate,
346               Object JavaDoc pArg0,
347               Object JavaDoc pArg1,
348               Object JavaDoc pArg2,
349               Object JavaDoc pArg3,
350               Object JavaDoc pArg4)
351     throws ELException JavaDoc
352   {
353     if (isLoggingWarning ()) {
354       logWarning
355     (MessageFormat.format
356      (pTemplate,
357       new Object JavaDoc [] {
358         "" + pArg0,
359         "" + pArg1,
360         "" + pArg2,
361         "" + pArg3,
362         "" + pArg4,
363       }));
364     }
365   }
366
367   //-------------------------------------
368
/**
369    *
370    * Logs a warning
371    **/

372   public void logWarning (String JavaDoc pTemplate,
373               Throwable JavaDoc pRootCause,
374               Object JavaDoc pArg0,
375               Object JavaDoc pArg1,
376               Object JavaDoc pArg2,
377               Object JavaDoc pArg3,
378               Object JavaDoc pArg4)
379     throws ELException JavaDoc
380   {
381     if (isLoggingWarning ()) {
382       logWarning
383     (MessageFormat.format
384      (pTemplate,
385       new Object JavaDoc [] {
386         "" + pArg0,
387         "" + pArg1,
388         "" + pArg2,
389         "" + pArg3,
390         "" + pArg4,
391       }),
392      pRootCause);
393     }
394   }
395
396   //-------------------------------------
397
/**
398    *
399    * Logs a warning
400    **/

401   public void logWarning (String JavaDoc pTemplate,
402               Object JavaDoc pArg0,
403               Object JavaDoc pArg1,
404               Object JavaDoc pArg2,
405               Object JavaDoc pArg3,
406               Object JavaDoc pArg4,
407               Object JavaDoc pArg5)
408     throws ELException JavaDoc
409   {
410     if (isLoggingWarning ()) {
411       logWarning
412     (MessageFormat.format
413      (pTemplate,
414       new Object JavaDoc [] {
415         "" + pArg0,
416         "" + pArg1,
417         "" + pArg2,
418         "" + pArg3,
419         "" + pArg4,
420         "" + pArg5,
421       }));
422     }
423   }
424
425   //-------------------------------------
426
/**
427    *
428    * Logs a warning
429    **/

430   public void logWarning (String JavaDoc pTemplate,
431               Throwable JavaDoc pRootCause,
432               Object JavaDoc pArg0,
433               Object JavaDoc pArg1,
434               Object JavaDoc pArg2,
435               Object JavaDoc pArg3,
436               Object JavaDoc pArg4,
437               Object JavaDoc pArg5)
438     throws ELException JavaDoc
439   {
440     if (isLoggingWarning ()) {
441       logWarning
442     (MessageFormat.format
443      (pTemplate,
444       new Object JavaDoc [] {
445         "" + pArg0,
446         "" + pArg1,
447         "" + pArg2,
448         "" + pArg3,
449         "" + pArg4,
450         "" + pArg5,
451       }),
452      pRootCause);
453     }
454   }
455
456   //-------------------------------------
457
/**
458    *
459    * Returns true if the application should even bother to try logging
460    * an error.
461    **/

462   public boolean isLoggingError ()
463   {
464     return true;
465   }
466
467   //-------------------------------------
468
/**
469    *
470    * Logs an error
471    **/

472   public void logError (String JavaDoc pMessage,
473             Throwable JavaDoc pRootCause)
474     throws ELException JavaDoc
475   {
476     if (isLoggingError ()) {
477       if (pMessage == null) {
478     throw new ELException JavaDoc (pRootCause);
479       }
480       else if (pRootCause == null) {
481     throw new ELException JavaDoc (pMessage);
482       }
483       else {
484     throw new ELException JavaDoc (pMessage, pRootCause);
485       }
486     }
487   }
488
489   //-------------------------------------
490
/**
491    *
492    * Logs an error
493    **/

494   public void logError (String JavaDoc pTemplate)
495     throws ELException JavaDoc
496   {
497     if (isLoggingError ()) {
498       logError (pTemplate, null);
499     }
500   }
501
502   //-------------------------------------
503
/**
504    *
505    * Logs an error
506    **/

507   public void logError (Throwable JavaDoc pRootCause)
508     throws ELException JavaDoc
509   {
510     if (isLoggingError ()) {
511       logError (null, pRootCause);
512     }
513   }
514
515   //-------------------------------------
516
/**
517    *
518    * Logs an error
519    **/

520   public void logError (String JavaDoc pTemplate,
521             Object JavaDoc pArg0)
522     throws ELException JavaDoc
523   {
524     if (isLoggingError ()) {
525       logError
526     (MessageFormat.format
527      (pTemplate,
528       new Object JavaDoc [] {
529         "" + pArg0,
530       }));
531     }
532   }
533
534   //-------------------------------------
535
/**
536    *
537    * Logs an error
538    **/

539   public void logError (String JavaDoc pTemplate,
540             Throwable JavaDoc pRootCause,
541             Object JavaDoc pArg0)
542     throws ELException JavaDoc
543   {
544     if (isLoggingError ()) {
545       logError
546     (MessageFormat.format
547      (pTemplate,
548       new Object JavaDoc [] {
549         "" + pArg0,
550       }),
551      pRootCause);
552     }
553   }
554
555   //-------------------------------------
556
/**
557    *
558    * Logs an error
559    **/

560   public void logError (String JavaDoc pTemplate,
561             Object JavaDoc pArg0,
562             Object JavaDoc pArg1)
563     throws ELException JavaDoc
564   {
565     if (isLoggingError ()) {
566       logError
567     (MessageFormat.format
568      (pTemplate,
569       new Object JavaDoc [] {
570         "" + pArg0,
571         "" + pArg1,
572       }));
573     }
574   }
575
576   //-------------------------------------
577
/**
578    *
579    * Logs an error
580    **/

581   public void logError (String JavaDoc pTemplate,
582             Throwable JavaDoc pRootCause,
583             Object JavaDoc pArg0,
584             Object JavaDoc pArg1)
585     throws ELException JavaDoc
586   {
587     if (isLoggingError ()) {
588       logError
589     (MessageFormat.format
590      (pTemplate,
591       new Object JavaDoc [] {
592         "" + pArg0,
593         "" + pArg1,
594       }),
595      pRootCause);
596     }
597   }
598
599   //-------------------------------------
600
/**
601    *
602    * Logs an error
603    **/

604   public void logError (String JavaDoc pTemplate,
605             Object JavaDoc pArg0,
606             Object JavaDoc pArg1,
607             Object JavaDoc pArg2)
608     throws ELException JavaDoc
609   {
610     if (isLoggingError ()) {
611       logError
612     (MessageFormat.format
613      (pTemplate,
614       new Object JavaDoc [] {
615         "" + pArg0,
616         "" + pArg1,
617         "" + pArg2,
618       }));
619     }
620   }
621
622   //-------------------------------------
623
/**
624    *
625    * Logs an error
626    **/

627   public void logError (String JavaDoc pTemplate,
628             Throwable JavaDoc pRootCause,
629             Object JavaDoc pArg0,
630             Object JavaDoc pArg1,
631             Object JavaDoc pArg2)
632     throws ELException JavaDoc
633   {
634     if (isLoggingError ()) {
635       logError
636     (MessageFormat.format
637      (pTemplate,
638       new Object JavaDoc [] {
639         "" + pArg0,
640         "" + pArg1,
641         "" + pArg2,
642       }),
643      pRootCause);
644     }
645   }
646
647   //-------------------------------------
648
/**
649    *
650    * Logs an error
651    **/

652   public void logError (String JavaDoc pTemplate,
653             Object JavaDoc pArg0,
654             Object JavaDoc pArg1,
655             Object JavaDoc pArg2,
656             Object JavaDoc pArg3)
657     throws ELException JavaDoc
658   {
659     if (isLoggingError ()) {
660       logError
661     (MessageFormat.format
662      (pTemplate,
663       new Object JavaDoc [] {
664         "" + pArg0,
665         "" + pArg1,
666         "" + pArg2,
667         "" + pArg3,
668       }));
669     }
670   }
671
672   //-------------------------------------
673
/**
674    *
675    * Logs an error
676    **/

677   public void logError (String JavaDoc pTemplate,
678             Throwable JavaDoc pRootCause,
679             Object JavaDoc pArg0,
680             Object JavaDoc pArg1,
681             Object JavaDoc pArg2,
682             Object JavaDoc pArg3)
683     throws ELException JavaDoc
684   {
685     if (isLoggingError ()) {
686       logError
687     (MessageFormat.format
688      (pTemplate,
689       new Object JavaDoc [] {
690         "" + pArg0,
691         "" + pArg1,
692         "" + pArg2,
693         "" + pArg3,
694       }),
695      pRootCause);
696     }
697   }
698
699   //-------------------------------------
700
/**
701    *
702    * Logs an error
703    **/

704   public void logError (String JavaDoc pTemplate,
705             Object JavaDoc pArg0,
706             Object JavaDoc pArg1,
707             Object JavaDoc pArg2,
708             Object JavaDoc pArg3,
709             Object JavaDoc pArg4)
710     throws ELException JavaDoc
711   {
712     if (isLoggingError ()) {
713       logError
714     (MessageFormat.format
715      (pTemplate,
716       new Object JavaDoc [] {
717         "" + pArg0,
718         "" + pArg1,
719         "" + pArg2,
720         "" + pArg3,
721         "" + pArg4,
722       }));
723     }
724   }
725
726   //-------------------------------------
727
/**
728    *
729    * Logs an error
730    **/

731   public void logError (String JavaDoc pTemplate,
732             Throwable JavaDoc pRootCause,
733             Object JavaDoc pArg0,
734             Object JavaDoc pArg1,
735             Object JavaDoc pArg2,
736             Object JavaDoc pArg3,
737             Object JavaDoc pArg4)
738     throws ELException JavaDoc
739   {
740     if (isLoggingError ()) {
741       logError
742     (MessageFormat.format
743      (pTemplate,
744       new Object JavaDoc [] {
745         "" + pArg0,
746         "" + pArg1,
747         "" + pArg2,
748         "" + pArg3,
749         "" + pArg4,
750       }),
751      pRootCause);
752     }
753   }
754
755   //-------------------------------------
756
/**
757    *
758    * Logs an error
759    **/

760   public void logError (String JavaDoc pTemplate,
761             Object JavaDoc pArg0,
762             Object JavaDoc pArg1,
763             Object JavaDoc pArg2,
764             Object JavaDoc pArg3,
765             Object JavaDoc pArg4,
766             Object JavaDoc pArg5)
767     throws ELException JavaDoc
768   {
769     if (isLoggingError ()) {
770       logError
771     (MessageFormat.format
772      (pTemplate,
773       new Object JavaDoc [] {
774         "" + pArg0,
775         "" + pArg1,
776         "" + pArg2,
777         "" + pArg3,
778         "" + pArg4,
779         "" + pArg5,
780       }));
781     }
782   }
783
784   //-------------------------------------
785
/**
786    *
787    * Logs an error
788    **/

789   public void logError (String JavaDoc pTemplate,
790             Throwable JavaDoc pRootCause,
791             Object JavaDoc pArg0,
792             Object JavaDoc pArg1,
793             Object JavaDoc pArg2,
794             Object JavaDoc pArg3,
795             Object JavaDoc pArg4,
796             Object JavaDoc pArg5)
797     throws ELException JavaDoc
798   {
799     if (isLoggingError ()) {
800       logError
801     (MessageFormat.format
802      (pTemplate,
803       new Object JavaDoc [] {
804         "" + pArg0,
805         "" + pArg1,
806         "" + pArg2,
807         "" + pArg3,
808         "" + pArg4,
809         "" + pArg5,
810       }),
811      pRootCause);
812     }
813   }
814
815   //-------------------------------------
816
}
817
Popular Tags