View Javadoc
1   package org.apache.maven.cli.logging;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.codehaus.plexus.logging.Logger;
23  import org.codehaus.plexus.logging.LoggerManager;
24  import org.slf4j.ILoggerFactory;
25  import org.slf4j.LoggerFactory;
26  
27  /**
28   * Use an SLF4J {@link org.slf4j.ILoggerFactory} as a backing for a Plexus {@link org.codehaus.plexus.logging.LoggerManager},
29   * ignoring Plexus logger API parts that are not classical and probably not really used.
30   *
31   * @author Jason van Zyl
32   * @since 3.1
33   */
34  public class Slf4jLoggerManager
35      implements LoggerManager
36  {
37  
38      private ILoggerFactory loggerFactory;
39  
40      public Slf4jLoggerManager()
41      {
42          loggerFactory = LoggerFactory.getILoggerFactory();
43      }
44  
45      public Logger getLoggerForComponent( String role )
46      {
47          return new Slf4jLogger( loggerFactory.getLogger( role ) );
48      }
49  
50      /**
51       * The logger name for a component with a non-null hint is <code>role.hint</code>.
52       * <b>Warning</b>: this does not conform to logger name as class name convention.
53       * (and what about <code>null</code> and <code>default</code> hint equivalence?)
54       */
55      public Logger getLoggerForComponent( String role, String hint )
56      {
57          return ( null == hint
58              ? getLoggerForComponent( role )
59              : new Slf4jLogger( loggerFactory.getLogger( role + '.' + hint ) ) );
60      }
61  
62      //
63      // Trying to give loggers back is a bad idea. Ceki said so :-)
64      // notice to self: what was this method supposed to do?
65      //
66      /**
67       * <b>Warning</b>: ignored.
68       */
69      public void returnComponentLogger( String role )
70      {
71      }
72  
73      /**
74       * <b>Warning</b>: ignored.
75       */
76      public void returnComponentLogger( String role, String hint )
77      {
78      }
79  
80      /**
81       * <b>Warning</b>: ignored (always return <code>0</code>).
82       */
83      public int getThreshold()
84      {
85          return 0;
86      }
87  
88      /**
89       * <b>Warning</b>: ignored.
90       */
91      public void setThreshold( int threshold )
92      {
93      }
94  
95      /**
96       * <b>Warning</b>: ignored.
97       */
98      public void setThresholds( int threshold )
99      {
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 }