01: /**
02: * Copyright (C) 2002
03: */package org.objectweb.util.monolog.wrapper.velocity;
04:
05: import org.apache.velocity.runtime.RuntimeServices;
06: import org.apache.velocity.runtime.log.LogSystem;
07: import org.objectweb.util.monolog.api.BasicLevel;
08: import org.objectweb.util.monolog.api.Logger;
09:
10: /**
11: * This class permits to connect the velocity log to a monolog system.
12: * To use this class you have to specify the logger that you want in the
13: * constructor.
14: *
15: * @author Sebastien Chassande-Barrioz
16: */
17: public class VelocityLogger implements LogSystem {
18:
19: private Logger log = null;
20:
21: public VelocityLogger(Logger l)
22: throws UnsupportedOperationException {
23: if (l == null) {
24: throw new UnsupportedOperationException(
25: "Null logger unsupported");
26: }
27: this .log = l;
28: }
29:
30: public void setLog(Logger l) {
31: if (l == null) {
32: throw new UnsupportedOperationException(
33: "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 {
49: if (log == null) {
50: throw new UnsupportedOperationException(
51: "Null logger unsupported");
52: }
53: }
54:
55: public void logVelocityMessage(int i, String s) {
56: if (i == LogSystem.WARN_ID) {
57: log.log(BasicLevel.WARN, s);
58: } else if (i == LogSystem.ERROR_ID) {
59: log.log(BasicLevel.ERROR, s);
60: } else if (i == LogSystem.INFO_ID) {
61: log.log(BasicLevel.INFO, s);
62: } else if (i == LogSystem.DEBUG_ID) {
63: log.log(BasicLevel.DEBUG, s);
64: }
65: }
66: }
|