Class LoggerManager
- java.lang.Object
-
- de.aristaflow.adept2.base.configuration.LoggerManager
-
- Direct Known Subclasses:
CsvLoggerManager
@ConfigurationDescription(properties={@Property(name="Logging.Instances.ConsoleLogger",defaultNull=true,documentationOnly=true,description="This is a global configuration and not specific to a LoggerManager. A list of instances for a console logger. All of these loggers will print to console. Note that the order of the log messages of different loggers may be arbitrary and even interleaved."),,,,,,,,,}) public abstract class LoggerManager extends Object
This class initialises and configures console and file loggers (handler) for the central logging, that is logging based on class names. This is the normal logging done in Java. However, one may also have loggers based on service instances, that is the full name of service instances. This class reads the following properties from the provided configuration:Logging.Instances.ConsoleLogger
(ConfigurationConstants.PREFIX_PROPERTY_REGISTRY_INSTANCES
,ConfigurationConstants.COMPONENT_TYPE_CONSOLE_LOGGER
)<ConsoleLoggerInstance>.Root
<ConsoleLoggerInstance>.Level
<ConsoleLoggerInstance>.Filter.Root
<ConsoleLoggerInstance>.Filter.Classes
(ConfigurationConstants.LOGGER_CONFIGURATION_CLASSES
)Logging.Instances.FileLogger
(ConfigurationConstants.PREFIX_PROPERTY_REGISTRY_INSTANCES
,ConfigurationConstants.COMPONENT_TYPE_FILE_LOGGER
)FileLogger.LogDirectory
(ConfigurationConstants.COMPONENT_TYPE_FILE_LOGGER
)<FileLoggerInstance>.Root
(ConfigurationConstants.LOGGER_CONFIGURATION_ROOT
)<FileLoggerInstance>.Level
(ConfigurationConstants.LOGGER_CONFIGURATION_LEVEL
)<FileLoggerInstance>.FileSize
(ConfigurationConstants.LOGGER_CONFIGURATION_FILE_SIZE
)<FileLoggerInstance>.FileCount
(ConfigurationConstants.LOGGER_CONFIGURATION_FILE_COUNT
)<FileLoggerInstance>.CSVMode
(ConfigurationConstants.LOGGER_CONFIGURATION_CSV_MODE
)<FileLoggerInstance>.Filter.Root
<FileLoggerInstance>.Filter.Classes
(ConfigurationConstants.LOGGER_CONFIGURATION_CLASSES
)
The filter is optional. If a root is specified, the log will only contain entries from classes which have the specified filter root as name prefix. If no filter level is specified, the level for the logger will be used.- Author:
- Ulrich Kreher
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Logger,Pair<Level,Collection<Handler>>>
configuredLoggers
All loggers that have a special configuration.protected static Logger
ourLogger
The logger for log messages when initialising all loggers.
-
Constructor Summary
Constructors Constructor Description LoggerManager(boolean keepHandler, boolean debugLogging)
Creates a new logger manager and initialises debug logging which applies until the console logging is initialised.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static void
adjustLogLevel(Level newLevel, Logger logger)
Adjusts the log level of the logger.protected abstract Formatter
createFormatter(boolean csvMode)
Creates a formatter for a logger.protected void
initialiseConsoleLogging(org.apache.commons.configuration2.Configuration configuration)
Initialises the console logging based on the designated configuration.protected void
initialiseFileLogging(org.apache.commons.configuration2.Configuration configuration, File globalLogDir)
Initialises the file logging based on the designated configuration.void
resetLogger()
Resets the configured loggers to their initial values and removes them from the map.
-
-
-
Field Detail
-
ourLogger
protected static final Logger ourLogger
The logger for log messages when initialising all loggers.
-
configuredLoggers
protected final Map<Logger,Pair<Level,Collection<Handler>>> configuredLoggers
All loggers that have a special configuration. They need to be strongly referenced somewhere since theLogManager
only keeps weak references to loggers. This way, loggers may be garbage-collected after they have been configured but before they are really used.
Besides the loggers the map also contains the initial log level and the log handlers added to each logger. This allows to reset the logger when terminating the platform.
-
-
Constructor Detail
-
LoggerManager
public LoggerManager(boolean keepHandler, boolean debugLogging)
Creates a new logger manager and initialises debug logging which applies until the console logging is initialised.- Parameters:
keepHandler
- Whether to keep already registered log handlers. Otherwise all registered log handlers will be removed.debugLogging
- Whether debug logging should be enabled, that is, all log messages before initialising the logging will be printed to console.
-
-
Method Detail
-
initialiseConsoleLogging
protected void initialiseConsoleLogging(org.apache.commons.configuration2.Configuration configuration)
Initialises the console logging based on the designated configuration. Reads all specified loggers, handlers and filters and their configuration and registers each with the corresponding logger.
If the log-level can not be determined, the corresponding logger will be ignored. If no logger-specific root is configured, the global root ("") will be used.- Parameters:
configuration
- The configuration containing the parameters for the console loggers, handlers and filters.
-
initialiseFileLogging
protected void initialiseFileLogging(org.apache.commons.configuration2.Configuration configuration, File globalLogDir) throws ConfigurationException
Initialises the file logging based on the designated configuration. Reads all specified loggers, handlers and filters and their configuration and registers each with the corresponding logger. Logs are appended to existing files.
If the log-level can not be determined, the corresponding logger will be ignored. If no logger-specific root is configured, the global root ("") will be used.- Parameters:
configuration
- The configuration containing the parameters for the file loggers and handlers.globalLogDir
- The directory for the logs which will be used if the designated configuration does not provide a log directory.- Throws:
ConfigurationException
- If the directory for storing the logs can not be created or it is a file, aConfigurationException
will be thrown.
-
createFormatter
protected abstract Formatter createFormatter(boolean csvMode)
Creates a formatter for a logger.- Parameters:
csvMode
- Whether the formatter is for a CSV log with additional AristaFlow-specific information when logging.- Returns:
- A formatter for a logger.
- See Also:
CSVFormatter
-
adjustLogLevel
public static void adjustLogLevel(Level newLevel, Logger logger)
Adjusts the log level of the logger. The log level of the logger will only be adjusted if it is higher (more severe) than the current log level of the logger. In case of an unset level, the level is inherited from the parent logger, so the parents are also checked. If a parent has a lower level, the designated logger will have its level adjusted. If a parent has a higher level, no adjustment will take place.- Parameters:
newLevel
- The new level for the logger.logger
- The logger for which to adjust the log level.
-
resetLogger
public void resetLogger()
Resets the configured loggers to their initial values and removes them from the map. That is all handler added for console or file logging will be closed and removed and the initial log level will be set.
-
-