01: /**
02: * Copyright (C) 2001-2005 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.jmx;
18:
19: import org.objectweb.util.monolog.Monolog;
20: import org.objectweb.util.monolog.api.BasicLevel;
21: import org.objectweb.util.monolog.api.Logger;
22:
23: /**
24: * This class is a wrapper permiting to use Monolog as logging system, in MX4J.
25: *
26: * @author S.Chassande-Barrioz
27: */
28: public class MX4JLoggerMonolog extends mx4j.log.Logger {
29:
30: /**
31: * The inner monolog Logger.
32: */
33: Logger logger;
34:
35: /**
36: * Builds a MX4JLoggerMonolog instance. MX4J requires an empty constructor.
37: */
38: public MX4JLoggerMonolog() {
39: }
40:
41: /**
42: * Builds a MX4JLoggerMonolog with a particular inner Logger.
43: * @param lo the inner logger
44: */
45: public MX4JLoggerMonolog(Logger lo) {
46: this .logger = lo;
47: }
48:
49: /**
50: * Assignes the name/topic of the logger. The inner logger is allocated at
51: * this time.
52: */
53: protected void setCategory(String name) {
54: super .setCategory(name);
55: logger = Monolog.monologFactory.getLogger(name);
56: }
57:
58: /**
59: * Assignes the priority/level on the logger.
60: */
61: public void setPriority(int p) {
62: super .setPriority(p);
63: logger.setIntLevel(priority2Level(p));
64: }
65:
66: /**
67: * Converts a priority (MX4J) to a level (Monolog)
68: */
69: private final static int priority2Level(int p) {
70: switch (p) {
71: case mx4j.log.Logger.FATAL:
72: return BasicLevel.FATAL;
73: case mx4j.log.Logger.ERROR:
74: return BasicLevel.ERROR;
75: case mx4j.log.Logger.WARN:
76: return BasicLevel.WARN;
77: case mx4j.log.Logger.INFO:
78: return BasicLevel.INFO;
79: case mx4j.log.Logger.DEBUG:
80: default:
81: return BasicLevel.DEBUG;
82: }
83: }
84:
85: /**
86: * Log the MX4J event into the inner monolog logger.
87: */
88: protected void log(int p, Object m, Throwable t) {
89: if (t == null) {
90: logger.log(priority2Level(p), m);
91: } else {
92: logger.log(priority2Level(p), m, t);
93: }
94: }
95: }
|