KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > Log4jXMLCLogger


1 /**
2   Log4jXMLCLogger - XMLC logger interface to the enhydra logger
3   
4
5     Copyright (C) 2002-2003 Together
6
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.
16
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21  Log4jXMLCLogger.java
22  Date: 14.07.2003.
23  @version 1.0.0
24  @author: Milosevic Sinisa sinisa@prozone.co.yu
25  */

26
27 package org.enhydra.xml.xmlc;
28
29 import org.apache.log4j.Level;
30
31 /**
32  * XMLC logger interface to the enhydra logger.
33  */

34 public class Log4jXMLCLogger implements XMLCLogger {
35
36   /**
37    * Constant for name of class to use when recording caller
38    * of log method. Appending a dot at the end is recommended practice.
39    */

40   private static final String JavaDoc FQCN = Log4jXMLCLogger.class.getName() + ".";
41
42   //underlying implementation
43
private final org.apache.log4j.Logger m_logger;
44
45   /**
46    * Create a logger that delegates to specified category.
47    *
48    * @param logImpl the category to delegate to
49    */

50   public Log4jXMLCLogger(final org.apache.log4j.Logger logImpl) {
51     m_logger = logImpl;
52   }
53
54
55   /**
56    * Determine if messages of priority "info" will be logged.
57    *
58    * @return true if "info" messages will be logged
59    */

60    public final boolean infoEnabled() {
61         return m_logger.isInfoEnabled();
62     }
63
64   /**
65    * Log a info message.
66    *
67    * @param message the message
68    */
public final void logInfo(final String JavaDoc message) {
69             m_logger.log(FQCN, Level.INFO, message, null );
70     }
71   /**
72    * Log a info message.
73    *
74    * @param message the message
75    * @param throwable the throwable
76    */

77     public final void logInfo(final String JavaDoc message, final Throwable JavaDoc throwable) {
78         m_logger.log( FQCN, Level.WARN, message, throwable );
79     }
80
81   /**
82    * Determine if messages of priority "error" will be logged.
83    *
84    * @return true if "error" messages will be logged
85    */

86     public final boolean errorEnabled() {
87         return m_logger.isEnabledFor(Level.ERROR);
88     }
89
90
91   /**
92    * Log a error message.
93    *
94    * @param message the message
95    */

96     public final void logError(final String JavaDoc message) {
97        m_logger.log( FQCN, Level.ERROR, message, null );
98     }
99
100   /**
101    * Log a error message.
102    *
103    * @param message the message
104    * @param throwable the throwable
105    */

106     public final void logError(final String JavaDoc message, final Throwable JavaDoc throwable) {
107        m_logger.log( FQCN, Level.ERROR, message, throwable );
108     }
109   
110   
111   /**
112    * Determine if messages of priority "debug" will be logged.
113    *
114    * @return true if "debug" messages will be logged
115    */

116     public boolean debugEnabled() {
117     return m_logger.isDebugEnabled();
118
119     }
120
121
122   /**
123    * Log a debug message.
124    *
125    * @param message the message
126    */

127     public final void logDebug(final String JavaDoc message) {
128         m_logger.log(FQCN, Level.DEBUG, message, null );
129     }
130
131
132   /**
133    * Log a debug message.
134    *
135    * @param message the message
136    * @param throwable the throwable
137    */

138     public void logDebug(final String JavaDoc message, final Throwable JavaDoc throwable) {
139         m_logger.log( FQCN, Level.DEBUG, message, throwable);
140     }
141     
142   /**
143    * Create a new child logger.
144    * The name of the child logger is [current-loggers-name].[passed-in-name]
145    * Throws <code>IllegalArgumentException</code> if name has an empty element name
146    *
147    * @param name the subname of this logger
148    * @return the new logger
149    */

150   public final XMLCLogger getChildLogger(final String JavaDoc name) {
151     return new Log4jXMLCLogger(
152       org.apache.log4j.Logger.getLogger(m_logger.getName() + "." + name));
153   }
154     
155 }
156
Popular Tags