Class LoggerManager

    • 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 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 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, 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:
        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.