summaryrefslogtreecommitdiff
path: root/python/skytools/scripting.py
diff options
context:
space:
mode:
authorMarko Kreen2011-11-08 08:16:35 +0000
committerMarko Kreen2011-11-08 08:16:35 +0000
commit2f3c68a44b8bc06b0b27856ae95465eb9eb8d821 (patch)
tree38e1a149e916f34e92a114e6382624875a3e95fc /python/skytools/scripting.py
parent16ef0fc09324c14556cfcdc906a25115fe0f74e8 (diff)
skytools.scripting: logging cleanup
- allow different log format when logging verbosely - don't assign to self.log during __init__, instead use class var This allows subclass var to override self.log
Diffstat (limited to 'python/skytools/scripting.py')
-rw-r--r--python/skytools/scripting.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/python/skytools/scripting.py b/python/skytools/scripting.py
index 6d19d223..f505d1e7 100644
--- a/python/skytools/scripting.py
+++ b/python/skytools/scripting.py
@@ -166,9 +166,12 @@ def _init_log(job_name, service_name, cf, log_level, is_daemon):
root.setLevel(log_level)
# compatibility: specify ini file in script config
+ def_fmt = '%(asctime)s %(process)s %(levelname)s %(message)s'
logfile = cf.getfile("logfile", "")
if logfile:
- fstr = cf.get('logfmt_file', '%(asctime)s %(process)s %(levelname)s %(message)s')
+ fstr = cf.get('logfmt_file', def_fmt)
+ if log_level < logging.INFO:
+ fstr = cf.get('logfmt_file_verbose', fstr)
fmt = logging.Formatter(fstr)
size = cf.getint('log_size', 10*1024*1024)
num = cf.getint('log_count', 3)
@@ -179,7 +182,9 @@ def _init_log(job_name, service_name, cf, log_level, is_daemon):
# 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')
+ fstr = cf.get('logfmt_console', def_fmt)
+ if log_level < logging.INFO:
+ fstr = cf.get('logfmt_console_verbose', fstr)
hdlr = logging.StreamHandler()
fmt = logging.Formatter(fstr)
hdlr.setFormatter(fmt)
@@ -220,7 +225,6 @@ class BaseScript(object):
service_name = None
job_name = None
cf = None
- log = None
pidfile = None
# >0 - sleep time if work() requests sleep
@@ -238,6 +242,9 @@ class BaseScript(object):
# -1 - exception was thrown
work_state = 1
+ # setup logger here, this allows override by subclass
+ log = logging.getLogger('skytools.BaseScript')
+
def __init__(self, service_name, args):
"""Script setup.
@@ -285,7 +292,7 @@ class BaseScript(object):
self.reload()
# init logging
- self.log = _init_log(self.job_name, self.service_name, self.cf, self.log_level, self.go_daemon)
+ _init_log(self.job_name, self.service_name, self.cf, self.log_level, self.go_daemon)
# send signal, if needed
if self.options.cmd == "kill":