View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH Munich, Germany (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.monitor;
24  
25  import org.apache.log4j.Logger;
26  import org.apache.log4j.Priority;
27  
28  import de.bea.domingo.DNotesMonitor;
29  
30  /***
31   * Adapter from Apache Log4j to the domingo monitor interface.
32   *
33   * <p>Use an instance of this class as argument to
34   * DNotesFactory.getInstance(DNotesMonitor theMonitor).</p>
35   *
36   * <p>If Log4j should be used for logging, the log4j.jar file must be available
37   * in the classpath. Log4h can be downloaded at
38   * <a target="_blank" href="http://logging.apache.org/log4j/"></a>.</p>
39   *
40   * @since domingo 1.1
41   */
42  public final class Log4jMonitor implements DNotesMonitor {
43  
44      /*** Reference to the log4j log that will receive all log messages from Domingo. */
45      private Logger logger;
46  
47      /***
48       * Constructor.
49       *
50       * <p>Creates a monitor with a default Logj log.</p>
51       */
52      public Log4jMonitor() {
53          this(Logger.getLogger(Log4jMonitor.class));
54      }
55  
56      /***
57       * Constructor.
58       *
59       * @param log a Log4j log instance
60       */
61      public Log4jMonitor(final Logger log) {
62          logger = log;
63      }
64  
65      /***
66       * Returns the current Log4j log.
67       *
68       * @return current Log4j log
69       */
70      public Logger getLogger() {
71          return logger;
72      }
73  
74      /***
75       * Sets a new Log4j log.
76       *
77       * @param log the new Log4j log
78       */
79      public void setLogger(final Logger log) {
80          this.logger = log;
81      }
82  
83      /***
84       * {@inheritDoc}
85       * @see de.bea.domingo.DNotesMonitor#debug(java.lang.String, java.lang.Throwable)
86       */
87      public void debug(final String message, final Throwable throwable) {
88          logger.debug(message, throwable);
89      }
90  
91      /***
92       * {@inheritDoc}
93       * @see de.bea.domingo.DNotesMonitor#debug(java.lang.String)
94       */
95      public void debug(final String message) {
96          logger.debug(message);
97      }
98  
99      /***
100      * {@inheritDoc}
101      * @see de.bea.domingo.DNotesMonitor#info(java.lang.String, java.lang.Throwable)
102      */
103     public void info(final String message, final Throwable throwable) {
104         logger.info(message, throwable);
105     }
106 
107     /***
108      * {@inheritDoc}
109      * @see de.bea.domingo.DNotesMonitor#info(java.lang.String)
110      */
111     public void info(final String message) {
112         logger.info(message);
113     }
114 
115     /***
116      * {@inheritDoc}
117      * @see de.bea.domingo.DNotesMonitor#warn(java.lang.String, java.lang.Throwable)
118      */
119     public void warn(final String message, final Throwable throwable) {
120         logger.warn(message, throwable);
121     }
122 
123     /***
124      * {@inheritDoc}
125      * @see de.bea.domingo.DNotesMonitor#warn(java.lang.String)
126      */
127     public void warn(final String message) {
128         logger.warn(message);
129     }
130 
131     /***
132      * {@inheritDoc}
133      * @see de.bea.domingo.DNotesMonitor#error(java.lang.String, java.lang.Throwable)
134      */
135     public void error(final String message, final Throwable throwable) {
136         logger.error(message, throwable);
137     }
138 
139     /***
140      * {@inheritDoc}
141      * @see de.bea.domingo.DNotesMonitor#error(java.lang.String)
142      */
143     public void error(final String message) {
144         logger.error(message);
145     }
146 
147     /***
148      * {@inheritDoc}
149      * @see de.bea.domingo.DNotesMonitor#fatalError(java.lang.String, java.lang.Throwable)
150      */
151     public void fatalError(final String message, final Throwable throwable) {
152         logger.fatal(message, throwable);
153     }
154 
155     /***
156      * {@inheritDoc}
157      * @see de.bea.domingo.DNotesMonitor#fatalError(java.lang.String)
158      */
159     public void fatalError(final String message) {
160         logger.fatal(message);
161     }
162 
163     /***
164      * {@inheritDoc}
165      * @see de.bea.domingo.DNotesMonitor#isDebugEnabled()
166      */
167     public boolean isDebugEnabled() {
168         return logger.isEnabledFor(Priority.DEBUG);
169     }
170 
171     /***
172      * {@inheritDoc}
173      * @see de.bea.domingo.DNotesMonitor#isInfoEnabled()
174      */
175     public boolean isInfoEnabled() {
176         return logger.isEnabledFor(Priority.INFO);
177     }
178 
179     /***
180      * {@inheritDoc}
181      * @see de.bea.domingo.DNotesMonitor#isWarnEnabled()
182      */
183     public boolean isWarnEnabled() {
184         return logger.isEnabledFor(Priority.WARN);
185     }
186 
187     /***
188      * {@inheritDoc}
189      * @see de.bea.domingo.DNotesMonitor#isErrorEnabled()
190      */
191     public boolean isErrorEnabled() {
192         return logger.isEnabledFor(Priority.ERROR);
193     }
194 
195     /***
196      * {@inheritDoc}
197      * @see de.bea.domingo.DNotesMonitor#isFatalErrorEnabled()
198      */
199     public boolean isFatalErrorEnabled() {
200         return logger.isEnabledFor(Priority.FATAL);
201     }
202 }