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: The log-directory for the file loggers can be absolute or relative. If no log directory is configured (neither as system property nor in the designated configuration), the system default will be used which is usually a directory "logs" in the current directory.
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 Details

    • 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 the LogManager 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 Details

    • 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 Details

    • initialiseConsoleLogging

      protected void initialiseConsoleLogging(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(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, a ConfigurationException 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:
    • 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.