001    /****************************************************************
002     * Licensed to the Apache Software Foundation (ASF) under one   *
003     * or more contributor license agreements.  See the NOTICE file *
004     * distributed with this work for additional information        *
005     * regarding copyright ownership.  The ASF licenses this file   *
006     * to you under the Apache License, Version 2.0 (the            *
007     * "License"); you may not use this file except in compliance   *
008     * with the License.  You may obtain a copy of the License at   *
009     *                                                              *
010     *   http://www.apache.org/licenses/LICENSE-2.0                 *
011     *                                                              *
012     * Unless required by applicable law or agreed to in writing,   *
013     * software distributed under the License is distributed on an  *
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015     * KIND, either express or implied.  See the License for the    *
016     * specific language governing permissions and limitations      *
017     * under the License.                                           *
018     ****************************************************************/
019    
020    package org.apache.james.jspf.impl;
021    
022    import org.apache.james.jspf.core.Logger;
023    import org.apache.log4j.Level;
024    
025    /**
026     * Implementation of the Logger interface using the Log4J implementation
027     * strategy.
028     */
029    public class Log4JLogger implements Logger {
030        private org.apache.log4j.Logger m_Logger;
031    
032        public Log4JLogger(org.apache.log4j.Logger log4jLogger) {
033            m_Logger = log4jLogger;
034        }
035    
036        /**
037         * Log a debug message.
038         * 
039         * @param message
040         *            the message
041         */
042        public void debug(String message) {
043            m_Logger.debug(message);
044        }
045    
046        /**
047         * Log a debug message.
048         * 
049         * @param message
050         *            the message
051         * @param throwable
052         *            the throwable
053         */
054        public void debug(String message, Throwable throwable) {
055            m_Logger.debug(message, throwable);
056        }
057    
058        /**
059         * Determine if messages of priority "debug" will be logged.
060         * 
061         * @return true if "debug" messages will be logged
062         */
063        public boolean isDebugEnabled() {
064            return m_Logger.isDebugEnabled();
065        }
066    
067        /**
068         * Log a info message.
069         * 
070         * @param message
071         *            the message
072         */
073        public void info(String message) {
074            m_Logger.info(message);
075        }
076    
077        /**
078         * Log a info message.
079         * 
080         * @param message
081         *            the message
082         * @param throwable
083         *            the throwable
084         */
085        public void info(String message, Throwable throwable) {
086            m_Logger.info(message, throwable);
087        }
088    
089        /**
090         * Determine if messages of priority "info" will be logged.
091         * 
092         * @return true if "info" messages will be logged
093         */
094        public boolean isInfoEnabled() {
095            return m_Logger.isInfoEnabled();
096        }
097    
098        /**
099         * Log a warn message.
100         * 
101         * @param message
102         *            the message
103         */
104        public void warn(String message) {
105            m_Logger.warn(message);
106        }
107    
108        /**
109         * Log a warn message.
110         * 
111         * @param message
112         *            the message
113         * @param throwable
114         *            the throwable
115         */
116        public void warn(String message, Throwable throwable) {
117            m_Logger.warn(message, throwable);
118        }
119    
120        /**
121         * Determine if messages of priority "warn" will be logged.
122         * 
123         * @return true if "warn" messages will be logged
124         */
125        public boolean isWarnEnabled() {
126            return m_Logger.isEnabledFor(Level.WARN);
127        }
128    
129        /**
130         * Log a error message.
131         * 
132         * @param message
133         *            the message
134         */
135        public void error(String message) {
136            m_Logger.error(message);
137        }
138    
139        /**
140         * Log a error message.
141         * 
142         * @param message
143         *            the message
144         * @param throwable
145         *            the throwable
146         */
147        public void error(String message, Throwable throwable) {
148            m_Logger.error(message, throwable);
149        }
150    
151        /**
152         * Determine if messages of priority "error" will be logged.
153         * 
154         * @return true if "error" messages will be logged
155         */
156        public boolean isErrorEnabled() {
157            return m_Logger.isEnabledFor(Level.ERROR);
158        }
159    
160        /**
161         * Log a fatalError message.
162         * 
163         * @param message
164         *            the message
165         */
166        public void fatalError(String message) {
167            m_Logger.fatal(message);
168        }
169    
170        /**
171         * Log a fatalError message.
172         * 
173         * @param message
174         *            the message
175         * @param throwable
176         *            the throwable
177         */
178        public void fatalError(String message, Throwable throwable) {
179            m_Logger.fatal(message, throwable);
180        }
181    
182        /**
183         * Determine if messages of priority "fatalError" will be logged.
184         * 
185         * @return true if "fatalError" messages will be logged
186         */
187        public boolean isFatalErrorEnabled() {
188            return m_Logger.isEnabledFor(Level.FATAL);
189        }
190    
191        /**
192         * Create a new child logger. The name of the child logger is
193         * [current-loggers-name].[passed-in-name] Throws
194         * <code>IllegalArgumentException</code> if name has an empty element name
195         * 
196         * @param name
197         *            the subname of this logger
198         * @return the new logger
199         */
200        public Logger getChildLogger(String name) {
201            String newName = m_Logger.getName() + "." + name;
202            org.apache.log4j.Logger childLog4JLogger = org.apache.log4j.Logger
203                    .getLogger(newName);
204            Log4JLogger child = new Log4JLogger(childLog4JLogger);
205            return child;
206        }
207    }