View Javadoc
1   package org.eclipse.aether.spi.log;
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  /**
23   * A logger factory that disables any logging.
24   *
25   * @deprecated Use SLF4J instead
26   */
27  @Deprecated
28  public final class NullLoggerFactory
29      implements LoggerFactory
30  {
31  
32      /**
33       * The singleton instance of this factory.
34       */
35      public static final LoggerFactory INSTANCE = new NullLoggerFactory();
36  
37      /**
38       * The singleton logger used by this factory.
39       */
40      public static final Logger LOGGER = new NullLogger();
41  
42      public Logger getLogger( String name )
43      {
44          return LOGGER;
45      }
46  
47      private NullLoggerFactory()
48      {
49          // hide constructor
50      }
51  
52      /**
53       * Gets a logger from the specified factory for the given class, falling back to a logger from this factory if the
54       * specified factory is {@code null} or fails to provide a logger.
55       *
56       * @param loggerFactory The logger factory from which to get the logger, may be {@code null}.
57       * @param type The class for which to get the logger, must not be {@code null}.
58       * @return The requested logger, never {@code null}.
59       */
60      public static Logger getSafeLogger( LoggerFactory loggerFactory, Class<?> type )
61      {
62          if ( loggerFactory == null )
63          {
64              return LOGGER;
65          }
66          Logger logger = loggerFactory.getLogger( type.getName() );
67          if ( logger == null )
68          {
69              return LOGGER;
70          }
71          return logger;
72      }
73  
74  }