Ejemplo n.º 1
0
def setup_logger(config):
    if config.has_option(SLACK_SECTION_NAME, "log_output"):
        output_path = config.get(SLACK_SECTION_NAME, "log_output")
        dir_path, file_name = os.path.split(output_path)
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)

        file_handler = RotatingFileHandler(output_path, backup_count=5)
        file_handler.push_application()
    else:
        stream_handler = StreamHandler(sys.stdout)
        stream_handler.push_application()
Ejemplo n.º 2
0
def setup_logger(conf):
    """ setup logger for app

    take conf, and set it.
    :param conf: a dict of logbook conf.

    """
    level_dict = {
        'notset': 9,
        'debug': 10,
        'info': 11,
        'warning': 12,
        'error': 13,
        'critical': 14
    }
    debug = conf['debug']
    logfile = conf['logfile']
    backup_count = conf['backup_count']
    max_size = conf['max_size']
    format_string = conf['format_string']
    level = level_dict[conf['level']]

    if debug:
        StreamHandler(sys.stdout, format_string=format_string,
                      level=level).push_application()
    else:

        full_log_path = os.path.abspath(logfile)
        dir_path = os.path.dirname(full_log_path)
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)

        RotatingFileHandler(logfile,
                            mode='a',
                            encoding='utf-8',
                            level=level,
                            format_string=format_string,
                            delay=False,
                            max_size=max_size,
                            backup_count=backup_count,
                            filter=None,
                            bubble=True).push_application()
Ejemplo n.º 3
0
def log_setup():
    log = RotatingFileHandler(applicationconfig.LOG_PATH,
                              max_size=104857600,
                              backup_count=5)
    log.push_application()