001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.kernel.log;
019    
020    import org.apache.commons.logging.Log;
021    import org.apache.log4j.ConsoleAppender;
022    import org.apache.log4j.Level;
023    import org.apache.log4j.Logger;
024    import org.apache.log4j.PatternLayout;
025    
026    /**
027     * Bootstrap log implementation for use with Log4j.
028     *
029     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
030     */
031    public class BootstrapLog4jLog implements Log {
032        static {
033            if (GeronimoLogging.isBootstrapLoggingInitializationEnabled()) {
034                Logger root = Logger.getRootLogger();
035                root.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
036    
037                GeronimoLogging level = GeronimoLogging.getDefaultLevel();
038                if (level == null) {
039                    root.setLevel(Level.ERROR);
040                } else if (level == GeronimoLogging.TRACE) {
041                    root.setLevel(Level.DEBUG);
042                } else if (level == GeronimoLogging.DEBUG) {
043                    root.setLevel(Level.DEBUG);
044                } else if (level == GeronimoLogging.INFO) {
045                    root.setLevel(Level.INFO);
046                } else if (level == GeronimoLogging.WARN) {
047                    root.setLevel(Level.WARN);
048                } else if (level == GeronimoLogging.ERROR) {
049                    root.setLevel(Level.ERROR);
050                } else if (level == GeronimoLogging.FATAL) {
051                    root.setLevel(Level.FATAL);
052                }
053            }
054        }
055    
056        private static final String FQCN = BootstrapLog4jLog.class.getName();
057        private Logger logger;
058    
059        public BootstrapLog4jLog(String name) {
060            logger = Logger.getLogger(name);
061        }
062    
063        public boolean isTraceEnabled() {
064            return logger.isEnabledFor(Level.DEBUG);
065        }
066    
067        public void trace(Object message) {
068            logger.log(FQCN, Level.DEBUG, message, null);
069        }
070    
071        public void trace(Object message, Throwable throwable) {
072            logger.log(FQCN, Level.DEBUG, message, throwable);
073        }
074    
075        public boolean isDebugEnabled() {
076            return logger.isEnabledFor(Level.DEBUG);
077        }
078    
079        public void debug(Object message) {
080            logger.log(FQCN, Level.DEBUG, message, null);
081        }
082    
083        public void debug(Object message, Throwable throwable) {
084            logger.log(FQCN, Level.DEBUG, message, throwable);
085        }
086    
087        public boolean isInfoEnabled() {
088            return logger.isEnabledFor(Level.INFO);
089        }
090    
091        public void info(Object message) {
092            logger.log(FQCN, Level.INFO, message, null);
093        }
094    
095        public void info(Object message, Throwable throwable) {
096            logger.log(FQCN, Level.INFO, message, throwable);
097        }
098    
099        public boolean isWarnEnabled() {
100            return logger.isEnabledFor(Level.WARN);
101        }
102    
103        public void warn(Object message) {
104            logger.log(FQCN, Level.WARN, message, null);
105        }
106    
107        public void warn(Object message, Throwable throwable) {
108            logger.log(FQCN, Level.WARN, message, throwable);
109        }
110    
111        public boolean isErrorEnabled() {
112            return logger.isEnabledFor(Level.ERROR);
113        }
114    
115        public void error(Object message) {
116            logger.log(FQCN, Level.ERROR, message, null);
117        }
118    
119        public void error(Object message, Throwable throwable) {
120            logger.log(FQCN, Level.ERROR, message, throwable);
121        }
122    
123        public boolean isFatalEnabled() {
124            return logger.isEnabledFor(Level.FATAL);
125        }
126    
127        public void fatal(Object message) {
128            logger.log(FQCN, Level.FATAL, message, null);
129        }
130    
131        public void fatal(Object message, Throwable throwable) {
132            logger.log(FQCN, Level.FATAL, message, throwable);
133        }
134    }