KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > monolog > wrapper > velocity > VelocityLogger


1 /**
2  * Copyright (C) 2002
3  */

4
5 package org.objectweb.util.monolog.wrapper.velocity;
6
7 import org.apache.velocity.runtime.RuntimeServices;
8 import org.apache.velocity.runtime.log.LogSystem;
9 import org.objectweb.util.monolog.api.BasicLevel;
10 import org.objectweb.util.monolog.api.Logger;
11
12 /**
13  * This class permits to connect the velocity log to a monolog system.
14  * To use this class you have to specify the logger that you want in the
15  * constructor.
16  *
17  * @author Sebastien Chassande-Barrioz
18  */

19 public class VelocityLogger implements LogSystem {
20
21     private Logger log = null;
22
23     public VelocityLogger(Logger l)
24         throws UnsupportedOperationException JavaDoc {
25         if (l == null) {
26             throw new UnsupportedOperationException JavaDoc("Null logger unsupported");
27         }
28         this.log = l;
29     }
30
31     public void setLog(Logger l) {
32         if (l == null) {
33             throw new UnsupportedOperationException JavaDoc("Null logger unsupported");
34         }
35         this.log = l;
36     }
37
38     public Logger getLog() {
39         return log;
40     }
41
42     // IMPLEMENTATION OF THE LogSystem INTERFACE //
43
//-------------------------------------------//
44

45     /**
46      * Nothing to do, except checking that the associated logger is not null.
47      */

48     public void init(RuntimeServices services) throws Exception JavaDoc {
49         if (log == null) {
50             throw new UnsupportedOperationException JavaDoc("Null logger unsupported");
51         }
52     }
53
54     public void logVelocityMessage(int i, String JavaDoc s) {
55         if (i == LogSystem.WARN_ID) {
56             log.log(BasicLevel.WARN, s);
57         }
58         else if (i == LogSystem.ERROR_ID) {
59             log.log(BasicLevel.ERROR, s);
60         }
61         else if (i == LogSystem.INFO_ID) {
62             log.log(BasicLevel.INFO, s);
63         }
64         else if (i == LogSystem.DEBUG_ID) {
65             log.log(BasicLevel.DEBUG, s);
66         }
67     }
68 }
69
Popular Tags