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
29   * {@link org.codehaus.plexus.logging.LoggerManager},
30   * ignoring Plexus logger API parts that are not classical and probably not really used.
31   *
32   * @author Jason van Zyl
33   * @since 3.1
34   */
35  public class Slf4jLoggerManager
36      implements LoggerManager
37  {
38  
39      private ILoggerFactory loggerFactory;
40  
41      public Slf4jLoggerManager()
42      {
43          loggerFactory = LoggerFactory.getILoggerFactory();
44      }
45  
46      public Logger getLoggerForComponent( String role )
47      {
48          return new Slf4jLogger( loggerFactory.getLogger( role ) );
49      }
50  
51      /**
52       * The logger name for a component with a non-null hint is <code>role.hint</code>.
53       * <b>Warning</b>: this does not conform to logger name as class name convention.
54       * (and what about <code>null</code> and <code>default</code> hint equivalence?)
55       */
56      public Logger getLoggerForComponent( String role, String hint )
57      {
58          return ( null == hint
59              ? getLoggerForComponent( role )
60              : new Slf4jLogger( loggerFactory.getLogger( role + '.' + hint ) ) );
61      }
62  
63      //
64      // Trying to give loggers back is a bad idea. Ceki said so :-)
65      // notice to self: what was this method supposed to do?
66      //
67      /**
68       * <b>Warning</b>: ignored.
69       */
70      public void returnComponentLogger( String role )
71      {
72      }
73  
74      /**
75       * <b>Warning</b>: ignored.
76       */
77      public void returnComponentLogger( String role, String hint )
78      {
79      }
80  
81      /**
82       * <b>Warning</b>: ignored (always return <code>0</code>).
83       */
84      public int getThreshold()
85      {
86          return 0;
87      }
88  
89      /**
90       * <b>Warning</b>: ignored.
91       */
92      public void setThreshold( int threshold )
93      {
94      }
95  
96      /**
97       * <b>Warning</b>: ignored.
98       */
99      public void setThresholds( int threshold )
100     {
101     }
102 
103     /**
104      * <b>Warning</b>: ignored (always return <code>0</code>).
105      */
106     public int getActiveLoggerCount()
107     {
108         return 0;
109     }
110 
111 }