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