示例#1
0
def config_logging():
    """Create a root logger with a stdout console handler with level=WARNING,
    and a file handler with level=DEBUG.
    Root logger level will be DEBUG.
    """
    # Defaults:
    #   attach_handlers_to_root=False,
    lcd = LCDict(log_path=LOG_PATH,
                 attach_handlers_to_root=True,
                 locking=True,
                 root_level='DEBUG')

    lcd.add_stdout_handler('console', level='WARNING', formatter='msg')

    # add a file handler, which will write to log_path + '/' + logfilename
    lcd.add_formatter(
        'my_file_formatter',
        format='%(levelname)-8s: %(message)s',
    )
    lcd.add_rotating_file_handler(
        'rot_fh',
        filename=LOGFILENAME,
        formatter='my_file_formatter',
        max_bytes=200,
        backup_count=10,
        mode='w',
    )
    # lcd.dump()           # | DEBUG

    lcd.config()
示例#2
0
def config_logging(use_locking):
    # NOTE: log_path dir should already exist
    log_path = os.path.join('_log/mproc_deco_rot_fh',
                            'LOCKING' if use_locking else 'NOLOCKING')
    lcd = LCDict(log_path=log_path,
                 root_level='DEBUG',
                 attach_handlers_to_root=True,
                 locking=use_locking)
    # Set up console handler to show process name, time, handler name
    lcd.add_stderr_handler('console',
                           formatter='process_level_msg',
                           level='INFO')
    # Add main file handler, which will write to log_path + '/' + logfilename
    lcd.add_rotating_file_handler(
        'rot_fh',
        filename=LOGFILENAME,
        # formatter='process_time_level_msg',
        max_bytes=1024,
        backup_count=10,
        # mode='w',
    )
    lcd.config()