001package org.apache.maven.cli.logging;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.codehaus.plexus.logging.Logger;
023import org.codehaus.plexus.logging.LoggerManager;
024import org.slf4j.ILoggerFactory;
025import org.slf4j.LoggerFactory;
026
027/**
028 * Use an SLF4J {@link org.slf4j.ILoggerFactory} as a backing for a Plexus {@link org.codehaus.plexus.logging.LoggerManager},
029 * ignoring Plexus logger API parts that are not classical and probably not really used.
030 *
031 * @author Jason van Zyl
032 * @since 3.1
033 */
034public class Slf4jLoggerManager
035    implements LoggerManager
036{
037
038    private ILoggerFactory loggerFactory;
039
040    public Slf4jLoggerManager()
041    {
042        loggerFactory = LoggerFactory.getILoggerFactory();
043    }
044
045    public Logger getLoggerForComponent( String role )
046    {
047        return new Slf4jLogger( loggerFactory.getLogger( role ) );
048    }
049
050    /**
051     * The logger name for a component with a non-null hint is <code>role.hint</code>.
052     * <b>Warning</b>: this does not conform to logger name as class name convention.
053     * (and what about <code>null</code> and <code>default</code> hint equivalence?)
054     */
055    public Logger getLoggerForComponent( String role, String hint )
056    {
057        return ( null == hint
058            ? getLoggerForComponent( role )
059            : new Slf4jLogger( loggerFactory.getLogger( role + '.' + hint ) ) );
060    }
061
062    //
063    // Trying to give loggers back is a bad idea. Ceki said so :-)
064    // notice to self: what was this method supposed to do?
065    //
066    /**
067     * <b>Warning</b>: ignored.
068     */
069    public void returnComponentLogger( String role )
070    {
071    }
072
073    /**
074     * <b>Warning</b>: ignored.
075     */
076    public void returnComponentLogger( String role, String hint )
077    {
078    }
079
080    /**
081     * <b>Warning</b>: ignored (always return <code>0</code>).
082     */
083    public int getThreshold()
084    {
085        return 0;
086    }
087
088    /**
089     * <b>Warning</b>: ignored.
090     */
091    public void setThreshold( int threshold )
092    {
093    }
094
095    /**
096     * <b>Warning</b>: ignored.
097     */
098    public void setThresholds( int threshold )
099    {
100    }
101
102    /**
103     * <b>Warning</b>: ignored (always return <code>0</code>).
104     */
105    public int getActiveLoggerCount()
106    {
107        return 0;
108    }
109
110}