def configure_logging():
    '''Configures the root logger for command line applications.

    Two stream handlers will be added to the logger:

        * "out" that will direct INFO & DEBUG messages to the standard output
        stream
        * "err" that will direct WARN, WARNING, ERROR, & CRITICAL messages to
        the standard error stream

    Note
    ----
    The level for individual loggers can be fine-tuned as follows (exemplified
    for the `tmlib` logger)::

        import logging

        logger = logging.getLogger('tmlib')
        logger.setLevel(logging.INFO)


    Warning
    -------
    Logging should only be configured once at the main entry point of the
    application!
    '''
    fmt = '[%(process)6d/%(threadName)-12s] %(asctime)s | %(levelname)-8s | %(name)-40s | %(message)s'
    datefmt = '%Y-%m-%d %H:%M:%S'
    formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)

    logger = logging.getLogger()  # returns the root logger

    stderr_handler = logging.StreamHandler(stream=sys.stderr)
    stderr_handler.name = 'err'
    stderr_handler.setLevel(logging.WARN)
    stderr_handler.setFormatter(formatter)
    logger.addHandler(stderr_handler)

    stdout_handler = logging.StreamHandler(stream=sys.stdout)
    stdout_handler.name = 'out'
    stdout_handler.setFormatter(formatter)
    stdout_handler.setLevel(0)
    stdout_handler.addFilter(InfoFilter())
    logger.addHandler(stdout_handler)
def configure_logging ( ) : fmt = '[%(process)6d/%(threadName)-12s] %(asctime)s | %(levelname)-8s | %(name)-40s | %(message)s' datefmt = '%Y-%m-%d %H:%M:%S' formatter = logging . Formatter ( fmt = fmt , datefmt = datefmt ) logger = logging . getLogger ( ) stderr_handler = logging . StreamHandler ( stream = sys . stderr ) stderr_handler . name = 'err' stderr_handler . setLevel ( logging . WARN ) stderr_handler . setFormatter ( formatter ) logger . addHandler ( stderr_handler ) stdout_handler = logging . StreamHandler ( stream = sys . stdout ) stdout_handler . name = 'out' stdout_handler . setFormatter ( formatter ) stdout_handler . setLevel ( 0 ) stdout_handler . addFilter ( InfoFilter ( ) ) logger . addHandler ( stdout_handler )
Configures the root logger for command line applications.

    Two stream handlers will be added to the logger:

        * "out" that will direct INFO & DEBUG messages to the standard output
        stream
        * "err" that will direct WARN, WARNING, ERROR, & CRITICAL messages to
        the standard error stream

    Note
    ----
    The level for individual loggers can be fine-tuned as follows (exemplified
    for the `tmlib` logger)::

        import logging

        logger = logging.getLogger('tmlib')
        logger.setLevel(logging.INFO)


    Warning
    -------
    Logging should only be configured once at the main entry point of the
    application!