com.clumd.projects.java_custom_logging.logging.ExtendedLoggerFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-custom-logging Show documentation
Show all versions of java-custom-logging Show documentation
A custom implementation of the SLF4J interface, but with bonuses for using it directly
The newest version!
package com.clumd.projects.java_custom_logging.logging;
import org.slf4j.ILoggerFactory;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.LogManager;
/**
* Basically directly copied from {@code org.slf4j.simple.SimpleLoggerFactory} but for my {@link ExtendedLogger}s
*/
public class ExtendedLoggerFactory implements ILoggerFactory {
private static final ConcurrentMap loggerMap = new ConcurrentHashMap<>();
@Override
public synchronized ExtendedSlf4jLogger getLogger(String name) {
ExtendedSlf4jLogger existingLogger = loggerMap.get(name);
if (existingLogger != null) {
return existingLogger;
}
// Create a logger under com.clumd version & keep track of it
ExtendedSlf4jLogger newInstance = new ExtendedSlf4jLogger(LogRoot.buildLogName(null, name));
loggerMap.put(name, newInstance);
// Integrate this new logger into the com.clumd management
LogManager.getLogManager().addLogger(newInstance);
LogRoot.updateThreadIdName(Thread.currentThread().threadId(), Thread.currentThread().getName());
return newInstance;
}
}