summaryrefslogtreecommitdiffstats
path: root/src/osmo_gsm_tester/log.py
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-05-24 18:31:01 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-05-28 22:26:23 +0000
commit9576f5f9a58be84f7767aba137f94300ec2b17bd (patch)
tree6ed6a362577d9b2a7d9c1875901a97a155eae23a /src/osmo_gsm_tester/log.py
parent445ff9b0f57b6cad356cc98c9c19598bde02d831 (diff)
log: change 'log_all_origins' from bool to a list of levels to apply to
The idea is to see the full origin list for log level ERR, while the rest of the logging can be kept less verbose. Change-Id: I0277782652548fa321f767da79b207d70678fad1
Diffstat (limited to 'src/osmo_gsm_tester/log.py')
-rw-r--r--src/osmo_gsm_tester/log.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/osmo_gsm_tester/log.py b/src/osmo_gsm_tester/log.py
index 1c069e7..3af7bbe 100644
--- a/src/osmo_gsm_tester/log.py
+++ b/src/osmo_gsm_tester/log.py
@@ -61,7 +61,7 @@ class LogTarget:
do_log_category = None
do_log_level = None
do_log_origin = None
- do_log_all_origins = None
+ do_log_all_origins_on_levels = None
do_log_traceback = None
do_log_src = None
origin_width = None
@@ -87,7 +87,7 @@ class LogTarget:
def remove(self):
LogTarget.all_targets.remove(self)
- def style(self, time=True, time_fmt=DATEFMT, category=True, level=True, origin=True, origin_width=32, src=True, trace=False, all_origins=True):
+ def style(self, time=True, time_fmt=DATEFMT, category=True, level=True, origin=True, origin_width=32, src=True, trace=False, all_origins_on_levels=(L_ERR, L_LOG, L_DBG, L_TRACEBACK)):
'''
set all logging format aspects, to defaults if not passed:
time: log timestamps;
@@ -98,6 +98,7 @@ class LogTarget:
origin_width: fill up the origin string with whitespace to this witdh;
src: log the source file and line number the log comes from;
trace: on exceptions, log the full stack trace;
+ all_origins_on_levels: pass a tuple of logging levels that should have a full trace of origins
'''
self.log_time_fmt = time_fmt
self.do_log_time = bool(time)
@@ -106,14 +107,14 @@ class LogTarget:
self.do_log_category = bool(category)
self.do_log_level = bool(level)
self.do_log_origin = bool(origin)
- self.do_log_all_origins = bool(all_origins)
self.origin_width = int(origin_width)
self.origin_fmt = '{:>%ds}' % self.origin_width
self.do_log_src = src
self.do_log_traceback = trace
+ self.do_log_all_origins_on_levels = tuple(all_origins_on_levels or [])
return self
- def style_change(self, time=None, time_fmt=None, category=None, level=None, origin=None, origin_width=None, src=None, trace=None, all_origins=None):
+ def style_change(self, time=None, time_fmt=None, category=None, level=None, origin=None, origin_width=None, src=None, trace=None, all_origins_on_levels=None):
'modify only the given aspects of the logging format'
self.style(
time=(time if time is not None else self.do_log_time),
@@ -124,7 +125,7 @@ class LogTarget:
origin_width=(origin_width if origin_width is not None else self.origin_width),
src=(src if src is not None else self.do_log_src),
trace=(trace if trace is not None else self.do_log_traceback),
- all_origins=(all_origins if all_origins is not None else self.do_log_all_origins),
+ all_origins_on_levels=(all_origins_on_levels if all_origins_on_levels is not None else self.do_log_all_origins_on_levels),
)
return self
@@ -190,7 +191,7 @@ class LogTarget:
log_line = [compose_message(messages, named_items)]
- if deeper_origins and self.do_log_all_origins:
+ if deeper_origins and (level in self.do_log_all_origins_on_levels):
log_line.append(' [%s]' % deeper_origins)
if self.do_log_src and src: