All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.slf4j.impl.ConsoleLoggerFactory Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) Aeontronix 2021
 */
package org.slf4j.impl;

import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ConsoleLoggerFactory implements ILoggerFactory {
    ConcurrentMap loggerMap;

    public ConsoleLoggerFactory() {
        loggerMap = new ConcurrentHashMap();
    }

    public Logger getLogger(String name) {
        Logger simpleLogger = loggerMap.get(name);
        if (simpleLogger != null) {
            return simpleLogger;
        } else {
            Logger newInstance = new ConsoleLogger(name);
            Logger oldInstance = loggerMap.putIfAbsent(name, newInstance);
            return oldInstance == null ? newInstance : oldInstance;
        }
    }

    /**
     * Clear the internal logger cache.
     *
     * This method is intended to be called by classes (in the same package) for
     * testing purposes. This method is internal. It can be modified, renamed or
     * removed at any time without notice.
     *
     * You are strongly discouraged from calling this method in production code.
     */
    void reset() {
        loggerMap.clear();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy