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