org.pixel.commons.logger.LogManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pixel-commons-linux Show documentation
Show all versions of pixel-commons-linux Show documentation
Java 2D Game Framework inspired on the popular XNA framework.
The newest version!
/*
* This software is available under Apache License
* Copyright (c) 2020
*/
package org.pixel.commons.logger;
import java.util.concurrent.ConcurrentHashMap;
public class LogManager {
//region Fields & Properties
private static final ConcurrentHashMap logContextMap = new ConcurrentHashMap<>();
private static LogLevel defaultLevel = LogLevel.DEBUG;
//endregion
//region Constructors
/**
* Private constructor
*/
private LogManager() {
// disable new instances..
}
//endregion
//region Public Functions
/**
* Creates or gets a logger context for a given class identifier
*
* @param classRef
* @return
*/
public static LoggerContext getContext(Class> classRef) {
return getContext(classRef.getSimpleName());
}
/**
* Creates or gets a logger context for a given identifier
*
* @param context
* @return
*/
public static LoggerContext getContext(String context) {
LoggerContext loggerContext = logContextMap.get(context);
if (loggerContext == null) {
loggerContext = new LoggerContext(context);
loggerContext.setLevel(defaultLevel);
logContextMap.put(context, loggerContext);
}
return loggerContext;
}
/**
* Sets the log level for all existing log contexts and assigns the new default log level
*
* @param level
*/
public static void setLogLevel(LogLevel level) {
logContextMap.forEach((s, loggerContext) -> loggerContext.setLevel(level));
setDefaultLogLevel(level);
}
/**
* Sets the default log level (applied when creating new loggers)
*
* @param level
*/
public static void setDefaultLogLevel(LogLevel level) {
defaultLevel = level;
}
/**
* Gets the default log level. To
*
* @return
*/
public static LogLevel getDefaultLogLevel() {
return defaultLevel;
}
//endregion
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy