001package org.eclipse.aether.spi.log;
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
022/**
023 * A logger factory that disables any logging.
024 *
025 * @deprecated Use SLF4J instead
026 */
027@Deprecated
028public final class NullLoggerFactory
029    implements LoggerFactory
030{
031
032    /**
033     * The singleton instance of this factory.
034     */
035    public static final LoggerFactory INSTANCE = new NullLoggerFactory();
036
037    /**
038     * The singleton logger used by this factory.
039     */
040    public static final Logger LOGGER = new NullLogger();
041
042    public Logger getLogger( String name )
043    {
044        return LOGGER;
045    }
046
047    private NullLoggerFactory()
048    {
049        // hide constructor
050    }
051
052    /**
053     * Gets a logger from the specified factory for the given class, falling back to a logger from this factory if the
054     * specified factory is {@code null} or fails to provide a logger.
055     *
056     * @param loggerFactory The logger factory from which to get the logger, may be {@code null}.
057     * @param type The class for which to get the logger, must not be {@code null}.
058     * @return The requested logger, never {@code null}.
059     */
060    public static Logger getSafeLogger( LoggerFactory loggerFactory, Class<?> type )
061    {
062        if ( loggerFactory == null )
063        {
064            return LOGGER;
065        }
066        Logger logger = loggerFactory.getLogger( type.getName() );
067        if ( logger == null )
068        {
069            return LOGGER;
070        }
071        return logger;
072    }
073
074}