Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/commons/el/Logger.java


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;
59  import java.text.MessageFormat;
60  import javax.servlet.jsp.el.ELException;
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 mOut;
84  
85    //-------------------------------------
86    /**
87     *
88     * Constructor
89     *
90     * @param pOut the PrintStream to which warnings should be printed
91     **/
92    public Logger (PrintStream 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 pMessage,
114         Throwable pRootCause)
115     throws ELException
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 pTemplate)
136     throws ELException
137   {
138     if (isLoggingWarning ()) {
139       logWarning (pTemplate, null);
140     }
141   }
142 
143   //-------------------------------------
144   /**
145    *
146    * Logs a warning
147    **/
148   public void logWarning (Throwable pRootCause)
149     throws ELException
150   {
151     if (isLoggingWarning ()) {
152       logWarning (null, pRootCause);
153     }
154   }
155 
156   //-------------------------------------
157   /**
158    *
159    * Logs a warning
160    **/
161   public void logWarning (String pTemplate,
162         Object pArg0)
163     throws ELException
164   {
165     if (isLoggingWarning ()) {
166       logWarning
167   (MessageFormat.format
168    (pTemplate,
169     new Object [] {
170       "" + pArg0,
171     }));
172     }
173   }
174 
175   //-------------------------------------
176   /**
177    *
178    * Logs a warning
179    **/
180   public void logWarning (String pTemplate,
181         Throwable pRootCause,
182         Object pArg0)
183     throws ELException
184   {
185     if (isLoggingWarning ()) {
186       logWarning
187   (MessageFormat.format
188    (pTemplate,
189     new Object [] {
190       "" + pArg0,
191     }),
192    pRootCause);
193     }
194   }
195 
196   //-------------------------------------
197   /**
198    *
199    * Logs a warning
200    **/
201   public void logWarning (String pTemplate,
202         Object pArg0,
203         Object pArg1)
204     throws ELException
205   {
206     if (isLoggingWarning ()) {
207       logWarning
208   (MessageFormat.format
209    (pTemplate,
210     new Object [] {
211       "" + pArg0,
212       "" + pArg1,
213     }));
214     }
215   }
216 
217   //-------------------------------------
218   /**
219    *
220    * Logs a warning
221    **/
222   public void logWarning (String pTemplate,
223         Throwable pRootCause,
224         Object pArg0,
225         Object pArg1)
226     throws ELException
227   {
228     if (isLoggingWarning ()) {
229       logWarning
230   (MessageFormat.format
231    (pTemplate,
232     new Object [] {
233       "" + pArg0,
234       "" + pArg1,
235     }),
236    pRootCause);
237     }
238   }
239 
240   //-------------------------------------
241   /**
242    *
243    * Logs a warning
244    **/
245   public void logWarning (String pTemplate,
246         Object pArg0,
247         Object pArg1,
248         Object pArg2)
249     throws ELException
250   {
251     if (isLoggingWarning ()) {
252       logWarning
253   (MessageFormat.format
254    (pTemplate,
255     new Object [] {
256       "" + pArg0,
257       "" + pArg1,
258       "" + pArg2,
259     }));
260     }
261   }
262 
263   //-------------------------------------
264   /**
265    *
266    * Logs a warning
267    **/
268   public void logWarning (String pTemplate,
269         Throwable pRootCause,
270         Object pArg0,
271         Object pArg1,
272         Object pArg2)
273     throws ELException
274   {
275     if (isLoggingWarning ()) {
276       logWarning
277   (MessageFormat.format
278    (pTemplate,
279     new Object [] {
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 pTemplate,
294         Object pArg0,
295         Object pArg1,
296         Object pArg2,
297         Object pArg3)
298     throws ELException
299   {
300     if (isLoggingWarning ()) {
301       logWarning
302   (MessageFormat.format
303    (pTemplate,
304     new Object [] {
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 pTemplate,
319         Throwable pRootCause,
320         Object pArg0,
321         Object pArg1,
322         Object pArg2,
323         Object pArg3)
324     throws ELException
325   {
326     if (isLoggingWarning ()) {
327       logWarning
328   (MessageFormat.format
329    (pTemplate,
330     new Object [] {
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 pTemplate,
346         Object pArg0,
347         Object pArg1,
348         Object pArg2,
349         Object pArg3,
350         Object pArg4)
351     throws ELException
352   {
353     if (isLoggingWarning ()) {
354       logWarning
355   (MessageFormat.format
356    (pTemplate,
357     new Object [] {
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 pTemplate,
373         Throwable pRootCause,
374         Object pArg0,
375         Object pArg1,
376         Object pArg2,
377         Object pArg3,
378         Object pArg4)
379     throws ELException
380   {
381     if (isLoggingWarning ()) {
382       logWarning
383   (MessageFormat.format
384    (pTemplate,
385     new Object [] {
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 pTemplate,
402         Object pArg0,
403         Object pArg1,
404         Object pArg2,
405         Object pArg3,
406         Object pArg4,
407         Object pArg5)
408     throws ELException
409   {
410     if (isLoggingWarning ()) {
411       logWarning
412   (MessageFormat.format
413    (pTemplate,
414     new Object [] {
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 pTemplate,
431         Throwable pRootCause,
432         Object pArg0,
433         Object pArg1,
434         Object pArg2,
435         Object pArg3,
436         Object pArg4,
437         Object pArg5)
438     throws ELException
439   {
440     if (isLoggingWarning ()) {
441       logWarning
442   (MessageFormat.format
443    (pTemplate,
444     new Object [] {
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 pMessage,
473       Throwable pRootCause)
474     throws ELException
475   {
476     if (isLoggingError ()) {
477       if (pMessage == null) {
478   throw new ELException (pRootCause);
479       }
480       else if (pRootCause == null) {
481   throw new ELException (pMessage);
482       }
483       else {
484   throw new ELException (pMessage, pRootCause);
485       }
486     }
487   }
488 
489   //-------------------------------------
490   /**
491    *
492    * Logs an error
493    **/
494   public void logError (String pTemplate)
495     throws ELException
496   {
497     if (isLoggingError ()) {
498       logError (pTemplate, null);
499     }
500   }
501 
502   //-------------------------------------
503   /**
504    *
505    * Logs an error
506    **/
507   public void logError (Throwable pRootCause)
508     throws ELException
509   {
510     if (isLoggingError ()) {
511       logError (null, pRootCause);
512     }
513   }
514 
515   //-------------------------------------
516   /**
517    *
518    * Logs an error
519    **/
520   public void logError (String pTemplate,
521       Object pArg0)
522     throws ELException
523   {
524     if (isLoggingError ()) {
525       logError
526   (MessageFormat.format
527    (pTemplate,
528     new Object [] {
529       "" + pArg0,
530     }));
531     }
532   }
533 
534   //-------------------------------------
535   /**
536    *
537    * Logs an error
538    **/
539   public void logError (String pTemplate,
540       Throwable pRootCause,
541       Object pArg0)
542     throws ELException
543   {
544     if (isLoggingError ()) {
545       logError
546   (MessageFormat.format
547    (pTemplate,
548     new Object [] {
549       "" + pArg0,
550     }),
551    pRootCause);
552     }
553   }
554 
555   //-------------------------------------
556   /**
557    *
558    * Logs an error
559    **/
560   public void logError (String pTemplate,
561       Object pArg0,
562       Object pArg1)
563     throws ELException
564   {
565     if (isLoggingError ()) {
566       logError
567   (MessageFormat.format
568    (pTemplate,
569     new Object [] {
570       "" + pArg0,
571       "" + pArg1,
572     }));
573     }
574   }
575 
576   //-------------------------------------
577   /**
578    *
579    * Logs an error
580    **/
581   public void logError (String pTemplate,
582       Throwable pRootCause,
583       Object pArg0,
584       Object pArg1)
585     throws ELException
586   {
587     if (isLoggingError ()) {
588       logError
589   (MessageFormat.format
590    (pTemplate,
591     new Object [] {
592       "" + pArg0,
593       "" + pArg1,
594     }),
595    pRootCause);
596     }
597   }
598 
599   //-------------------------------------
600   /**
601    *
602    * Logs an error
603    **/
604   public void logError (String pTemplate,
605       Object pArg0,
606       Object pArg1,
607       Object pArg2)
608     throws ELException
609   {
610     if (isLoggingError ()) {
611       logError
612   (MessageFormat.format
613    (pTemplate,
614     new Object [] {
615       "" + pArg0,
616       "" + pArg1,
617       "" + pArg2,
618     }));
619     }
620   }
621 
622   //-------------------------------------
623   /**
624    *
625    * Logs an error
626    **/
627   public void logError (String pTemplate,
628       Throwable pRootCause,
629       Object pArg0,
630       Object pArg1,
631       Object pArg2)
632     throws ELException
633   {
634     if (isLoggingError ()) {
635       logError
636   (MessageFormat.format
637    (pTemplate,
638     new Object [] {
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 pTemplate,
653       Object pArg0,
654       Object pArg1,
655       Object pArg2,
656       Object pArg3)
657     throws ELException
658   {
659     if (isLoggingError ()) {
660       logError
661   (MessageFormat.format
662    (pTemplate,
663     new Object [] {
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 pTemplate,
678       Throwable pRootCause,
679       Object pArg0,
680       Object pArg1,
681       Object pArg2,
682       Object pArg3)
683     throws ELException
684   {
685     if (isLoggingError ()) {
686       logError
687   (MessageFormat.format
688    (pTemplate,
689     new Object [] {
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 pTemplate,
705       Object pArg0,
706       Object pArg1,
707       Object pArg2,
708       Object pArg3,
709       Object pArg4)
710     throws ELException
711   {
712     if (isLoggingError ()) {
713       logError
714   (MessageFormat.format
715    (pTemplate,
716     new Object [] {
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 pTemplate,
732       Throwable pRootCause,
733       Object pArg0,
734       Object pArg1,
735       Object pArg2,
736       Object pArg3,
737       Object pArg4)
738     throws ELException
739   {
740     if (isLoggingError ()) {
741       logError
742   (MessageFormat.format
743    (pTemplate,
744     new Object [] {
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 pTemplate,
761       Object pArg0,
762       Object pArg1,
763       Object pArg2,
764       Object pArg3,
765       Object pArg4,
766       Object pArg5)
767     throws ELException
768   {
769     if (isLoggingError ()) {
770       logError
771   (MessageFormat.format
772    (pTemplate,
773     new Object [] {
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 pTemplate,
790       Throwable pRootCause,
791       Object pArg0,
792       Object pArg1,
793       Object pArg2,
794       Object pArg3,
795       Object pArg4,
796       Object pArg5)
797     throws ELException
798   {
799     if (isLoggingError ()) {
800       logError
801   (MessageFormat.format
802    (pTemplate,
803     new Object [] {
804       "" + pArg0,
805       "" + pArg1,
806       "" + pArg2,
807       "" + pArg3,
808       "" + pArg4,
809       "" + pArg5,
810     }),
811    pRootCause);
812     }
813   }
814 
815   //-------------------------------------
816 }