diff options
author | Marko Kreen | 2011-10-14 06:32:29 +0000 |
---|---|---|
committer | Marko Kreen | 2011-10-14 06:32:29 +0000 |
commit | 21c478d2eb241e049452f13e4f8191dce4cea5a9 (patch) | |
tree | a49e8c5f9ac1936b268cb134db684d142b832f5e /python/skytools/scripting.py | |
parent | a8a808511578823d1cbc281a258e9d7370aaa845 (diff) |
skytools.scripting: make non-skylog logging attach to root
use_skylog logging was already doing it. Now that simple
logging does it do, using self.log is not mandatory anymore,
code can use 'logging' module directly.
Also make console and logfile output configurable.
Diffstat (limited to 'python/skytools/scripting.py')
-rw-r--r-- | python/skytools/scripting.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py index a7eb7915..d671954d 100644 --- a/python/skytools/scripting.py +++ b/python/skytools/scripting.py @@ -161,25 +161,29 @@ def _init_log(job_name, service_name, cf, log_level, is_daemon): 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 logfile = cf.getfile("logfile", "") if logfile: - fmt = logging.Formatter('%(asctime)s %(process)s %(levelname)s %(message)s') + fstr = cf.get('logfmt_file', '%(asctime)s %(process)s %(levelname)s %(message)s') + fmt = logging.Formatter(fstr) 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) - log.addHandler(hdlr) + 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', '%(asctime)s %(process)s %(levelname)s %(message)s') hdlr = logging.StreamHandler() - fmt = logging.Formatter('%(asctime)s %(process)s %(levelname)s %(message)s') + fmt = logging.Formatter(fstr) hdlr.setFormatter(fmt) - log.addHandler(hdlr) - - log.setLevel(log_level) + root.addHandler(hdlr) return log |