(job_name, service_name, cf, log_level, is_daemon)
return log
Logging setup happens here.
Logging setup happens here.
Logging setup happens here .
def _init_log(job_name, service_name, cf, log_level, is_daemon):
    """Logging setup happens here."""
    global _log_init_done, _log_config_done

    got_skylog = 0
    use_skylog = cf.getint("use_skylog", default_skylog)

    # if non-daemon, avoid skylog if script is running on console.
    # set use_skylog=2 to disable.
    if not is_daemon and use_skylog == 1:
        if os.isatty(sys.stdout.fileno()):
            use_skylog = 0

    # load logging config if needed
    if use_skylog and not _log_config_done:
        # python logging.config braindamage:
        # cannot specify external classess without such hack
        logging.skylog = skytools.skylog
        skytools.skylog.set_service_name(service_name, job_name)

        # load general config
        flist = cf.getlist('skylog_locations',
                           ['skylog.ini', '~/.skylog.ini', '/etc/skylog.ini'])
        for fn in flist:
            fn = os.path.expanduser(fn)
            if os.path.isfile(fn):
                defs = {'job_name': job_name, 'service_name': service_name}
                _load_log_config(fn, defs)
                got_skylog = 1
                break
        _log_config_done = 1
        if not got_skylog:
            sys.stderr.write("skylog.ini not found!\n")
            sys.exit(1)

    # avoid duplicate logging init for job_name
    log = logging.getLogger(job_name)
    if job_name in _log_init_done:
        return log
    _log_init_done[job_name] = 1

    # tune level on root logger
    root = logging.getLogger()
    root.setLevel(log_level)

    # compatibility: specify ini file in script config
    def_fmt = '%(asctime)s %(process)s %(levelname)s %(message)s'
    def_datefmt = '' # None
    logfile = cf.getfile("logfile", "")
    if logfile:
        fstr = cf.get('logfmt_file', def_fmt)
        fstr_date = cf.get('logdatefmt_file', def_datefmt)
        if log_level < logging.INFO:
            fstr = cf.get('logfmt_file_verbose', fstr)
            fstr_date = cf.get('logdatefmt_file_verbose', fstr_date)
        fmt = logging.Formatter(fstr, fstr_date)
        size = cf.getint('log_size', 10*1024*1024)
        num = cf.getint('log_count', 3)
        hdlr = logging.handlers.RotatingFileHandler(
                    logfile, 'a', size, num)
        hdlr.setFormatter(fmt)
        root.addHandler(hdlr)

    # if skylog.ini is disabled or not available, log at least to stderr
    if not got_skylog:
        fstr = cf.get('logfmt_console', def_fmt)
        fstr_date = cf.get('logdatefmt_console', def_datefmt)
        if log_level < logging.INFO:
            fstr = cf.get('logfmt_console_verbose', fstr)
            fstr_date = cf.get('logdatefmt_console_verbose', fstr_date)
        hdlr = logging.StreamHandler()
        fmt = logging.Formatter(fstr, fstr_date)
        hdlr.setFormatter(fmt)
        root.addHandler(hdlr)

    return log
def _init_log ( job_name , service_name , cf , log_level , is_daemon ) : global _log_init_done , _log_config_done got_skylog = 0 use_skylog = cf . getint ( "use_skylog" , default_skylog ) # if non-daemon, avoid skylog if script is running on console. # set use_skylog=2 to disable. if not is_daemon and use_skylog == 1 : if os . isatty ( sys . stdout . fileno ( ) ) : use_skylog = 0 # load logging config if needed if use_skylog and not _log_config_done : # python logging.config braindamage: # cannot specify external classess without such hack logging . skylog = skytools . skylog skytools . skylog . set_service_name ( service_name , job_name ) # load general config flist = cf . getlist ( 'skylog_locations' , [ 'skylog.ini' , '~/.skylog.ini' , '/etc/skylog.ini' ] ) for fn in flist : fn = os . path . expanduser ( fn ) if os . path . isfile ( fn ) : defs = { 'job_name' : job_name , 'service_name' : service_name } _load_log_config ( fn , defs ) got_skylog = 1 break _log_config_done = 1 if not got_skylog : sys . stderr . write ( "skylog.ini not found!\n" ) sys . exit ( 1 ) # avoid duplicate logging init for job_name log = logging . getLogger ( job_name ) if job_name in _log_init_done : return log _log_init_done [ job_name ] = 1 # tune level on root logger root = logging . getLogger ( ) root . setLevel ( log_level ) # compatibility: specify ini file in script config def_fmt = '%(asctime)s %(process)s %(levelname)s %(message)s' def_datefmt = '' # None logfile = cf . getfile ( "logfile" , "" ) if logfile : fstr = cf . get ( 'logfmt_file' , def_fmt ) fstr_date = cf . get ( 'logdatefmt_file' , def_datefmt ) if log_level < logging . INFO : fstr = cf . get ( 'logfmt_file_verbose' , fstr ) fstr_date = cf . get ( 'logdatefmt_file_verbose' , fstr_date ) fmt = logging . Formatter ( fstr , fstr_date ) size = cf . getint ( 'log_size' , 10 * 1024 * 1024 ) num = cf . getint ( 'log_count' , 3 ) hdlr = logging . handlers . RotatingFileHandler ( logfile , 'a' , size , num ) hdlr . setFormatter ( fmt ) root . addHandler ( hdlr ) # if skylog.ini is disabled or not available, log at least to stderr if not got_skylog : fstr = cf . get ( 'logfmt_console' , def_fmt ) fstr_date = cf . get ( 'logdatefmt_console' , def_datefmt ) if log_level < logging . INFO : fstr = cf . get ( 'logfmt_console_verbose' , fstr ) fstr_date = cf . get ( 'logdatefmt_console_verbose' , fstr_date ) hdlr = logging . StreamHandler ( ) fmt = logging . Formatter ( fstr , fstr_date ) hdlr . setFormatter ( fmt ) root . addHandler ( hdlr ) return log