Exemple #1
0
def initialize(propagate=None):
    """Initialize all logs.

    :param propagate: Flag specifying whether logs should propagate their
        messages to the root logger.  If omitted, propagation is determined
        from the configuration files.
    :type propagate: bool or None
    """
    # First, find the root logger and configure the logging subsystem.
    # Initialize the root logger, then create a formatter for all the
    # sublogs.  The root logger should log to stderr.
    logging.basicConfig(format=config.logging.root.format,
                        datefmt=config.logging.root.datefmt,
                        level=as_log_level(config.logging.root.level))
    # Create the sub-loggers.  Note that we'll redirect flufl.lock to
    # mailman.locks.
    for logger_config in config.logger_configs:
        sub_name = logger_config.name.split('.')[-1]
        if sub_name == 'root':
            continue
        if sub_name == 'locks':
            log = logging.getLogger('flufl.lock')
        if sub_name == 'database':
            # Set both the SQLAlchemy and Alembic logs to the mailman.database
            # log configuration, essentially ignoring the alembic.cfg settings.
            # Do the SQLAlchemy one first, then let the Alembic one fall
            # through to the common code path.
            log = logging.getLogger('sqlalchemy')
            _init_logger(propagate, sub_name, log, logger_config)
            log = logging.getLogger('alembic')
        else:
            logger_name = 'mailman.' + sub_name
            log = logging.getLogger(logger_name)
        _init_logger(propagate, sub_name, log, logger_config)
Exemple #2
0
def initialize(propagate=None):
    """Initialize all logs.

    :param propagate: Flag specifying whether logs should propagate their
        messages to the root logger.  If omitted, propagation is determined
        from the configuration files.
    :type propagate: bool or None
    """
    # First, find the root logger and configure the logging subsystem.
    # Initialize the root logger, then create a formatter for all the
    # sublogs.  The root logger should log to stderr.
    logging.basicConfig(format=config.logging.root.format,
                        datefmt=config.logging.root.datefmt,
                        level=as_log_level(config.logging.root.level),
                        stream=sys.stderr)
    # Create the sub-loggers.  Note that we'll redirect flufl.lock to
    # mailman.locks.
    for logger_config in config.logger_configs:
        sub_name = logger_config.name.split('.')[-1]
        if sub_name == 'root':
            continue
        if sub_name == 'locks':
            log = logging.getLogger('flufl.lock')
        else:
            logger_name = 'mailman.' + sub_name
            log = logging.getLogger(logger_name)
        # Get settings from log configuration file (or defaults).
        log_format = logger_config.format
        log_datefmt = logger_config.datefmt
        # Propagation to the root logger is how we handle logging to stderr
        # when the runners are not run as a subprocess of 'bin/mailman start'.
        log.propagate = (as_boolean(logger_config.propagate)
                         if propagate is None else propagate)
        # Set the logger's level.
        log.setLevel(as_log_level(logger_config.level))
        # Create a formatter for this logger, then a handler, and link the
        # formatter to the handler.
        formatter = logging.Formatter(fmt=log_format, datefmt=log_datefmt)
        path_str = logger_config.path
        path_abs = os.path.normpath(os.path.join(config.LOG_DIR, path_str))
        handler = ReopenableFileHandler(sub_name, path_abs)
        _handlers[sub_name] = handler
        handler.setFormatter(formatter)
        log.addHandler(handler)
Exemple #3
0
def _init_logger(propagate, sub_name, log, logger_config):
    # Get settings from log configuration file (or defaults).
    log_format = logger_config.format
    log_datefmt = logger_config.datefmt
    # Propagation to the root logger is how we handle logging to stderr when
    # the runners are not run as a subprocess of 'mailman start'.
    log.propagate = (as_boolean(logger_config.propagate)
                     if propagate is None else propagate)
    # Set the logger's level.
    log.setLevel(as_log_level(logger_config.level))
    # Create a formatter for this logger, then a handler, and link the
    # formatter to the handler.
    formatter = logging.Formatter(fmt=log_format, datefmt=log_datefmt)
    path_str = logger_config.path
    path_abs = os.path.normpath(os.path.join(config.LOG_DIR, path_str))
    handler = ReopenableFileHandler(sub_name, path_abs)
    _handlers[sub_name] = handler
    handler.setFormatter(formatter)
    log.addHandler(handler)
Exemple #4
0
def _init_logger(propagate, sub_name, log, logger_config):
    # Get settings from log configuration file (or defaults).
    log_format = logger_config.format
    log_datefmt = logger_config.datefmt
    # Propagation to the root logger is how we handle logging to stderr
    # when the runners are not run as a subprocess of 'bin/mailman start'.
    log.propagate = (as_boolean(logger_config.propagate)
                     if propagate is None else propagate)
    # Set the logger's level.
    log.setLevel(as_log_level(logger_config.level))
    # Create a formatter for this logger, then a handler, and link the
    # formatter to the handler.
    formatter = logging.Formatter(fmt=log_format, datefmt=log_datefmt)
    path_str = logger_config.path
    path_abs = os.path.normpath(os.path.join(config.LOG_DIR, path_str))
    handler = ReopenableFileHandler(sub_name, path_abs)
    _handlers[sub_name] = handler
    handler.setFormatter(formatter)
    log.addHandler(handler)
def initialize(propagate=None):
    """Initialize all logs.

    :param propagate: Flag specifying whether logs should propagate their
        messages to the root logger.  If omitted, propagation is determined
        from the configuration files.
    :type propagate: bool or None
    """
    # First, find the root logger and configure the logging subsystem.
    # Initialize the root logger, then create a formatter for all the
    # sublogs.  The root logger should log to stderr.
    logging.basicConfig(format=config.logging.root.format,
                        datefmt=config.logging.root.datefmt,
                        level=as_log_level(config.logging.root.level))
    # Create the sub-loggers.  Note that we'll redirect flufl.lock to
    # mailman.locks.
    for logger_config in config.logger_configs:
        sub_name = logger_config.name.split('.')[-1]
        if sub_name == 'root':
            continue
        if sub_name == 'locks':
            log = logging.getLogger('flufl.lock')
            # Explicitly prevent flufl.lock from propagating its log messages
            # to its root logger, i.e. the console.
            log.propagate = False
        if sub_name == 'database':
            # Set both the SQLAlchemy and Alembic logs to the mailman.database
            # log configuration, essentially ignoring the alembic.cfg settings.
            # Do the SQLAlchemy one first, then let the Alembic one fall
            # through to the common code path.
            log = logging.getLogger('sqlalchemy')
            _init_logger(propagate, sub_name, log, logger_config)
            log = logging.getLogger('alembic')
        elif sub_name == 'smtp':
            log = logging.getLogger('mail.log')
            _init_logger(propagate, sub_name, log, logger_config)
            log = logging.getLogger('mailman.smtp')
        else:
            logger_name = 'mailman.' + sub_name
            log = logging.getLogger(logger_name)
        _init_logger(propagate, sub_name, log, logger_config)