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.geronimo.gshell;
021    
022    import org.codehaus.plexus.logging.AbstractLogger;
023    import org.codehaus.plexus.logging.BaseLoggerManager;
024    import org.slf4j.Logger;
025    import org.slf4j.LoggerFactory;
026    
027    /**
028     * Adapts the Plexus logging system to SLF4J.
029     *
030     * @version $Rev: 573970 $ $Date: 2007-09-09 02:22:11 -0700 (Sun, 09 Sep 2007) $
031     */
032    public class Slf4jLoggingManager
033        extends BaseLoggerManager
034    {
035        protected org.codehaus.plexus.logging.Logger createLogger(final String key) {
036            return new LoggerImpl(getThreshold(), LoggerFactory.getLogger(key));
037        }
038    
039        /**
040         * Adapts the Plexus {@link org.codehaus.plexus.logging.Logger} interface to SLF4J
041         */
042        public static class LoggerImpl
043            extends AbstractLogger
044        {
045            private final Logger log;
046    
047            public LoggerImpl(final int threshold, final Logger logger) {
048                super(threshold, logger.getName());
049    
050                this.log = logger;
051            }
052    
053            public void debug(final String message, final Throwable throwable) {
054                log.debug( message, throwable );
055            }
056    
057            public void error(final String message, final Throwable throwable) {
058                log.error(message, throwable);
059            }
060    
061            public void fatalError(final String message, final Throwable throwable) {
062                log.error(message, throwable);
063            }
064    
065            public org.codehaus.plexus.logging.Logger getChildLogger(final String name) {
066                String childName = log.getName() + "." + name;
067    
068                return new LoggerImpl(getThreshold(), LoggerFactory.getLogger(childName));
069            }
070    
071            public void info(String message, final Throwable throwable) {
072                log.info(message, throwable);
073            }
074    
075            public void warn(String message, final Throwable throwable) {
076                log.warn(message, throwable);
077            }
078        }
079    }