[PATCH] osmo-gsm-tester[master]: log: change 'log_all_origins' from bool to a list of levels ...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu May 25 02:57:22 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/2731

to look at the new patch set (#2).

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
---
M src/osmo-gsm-tester.py
M src/osmo_gsm_tester/log.py
M src/osmo_gsm_tester/trial.py
3 files changed, 9 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/31/2731/2

diff --git a/src/osmo-gsm-tester.py b/src/osmo-gsm-tester.py
index 9b7ae25..53a1dab 100755
--- a/src/osmo-gsm-tester.py
+++ b/src/osmo-gsm-tester.py
@@ -129,7 +129,7 @@
     print('tests:', repr(args.test))
 
     # create a default log to stdout
-    log.LogTarget().style(all_origins=False, src=False)
+    log.LogTarget().style(all_origins_on_levels=(log.L_ERR, log.L_TRACEBACK), src=False)
 
     if args.log_level:
         log.set_all_levels(log.LEVEL_STRS.get(args.log_level))
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 @@
     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 @@
     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 @@
         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 @@
         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 @@
             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 @@
 
         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:
diff --git a/src/osmo_gsm_tester/trial.py b/src/osmo_gsm_tester/trial.py
index 3eb0c67..fba473f 100644
--- a/src/osmo_gsm_tester/trial.py
+++ b/src/osmo_gsm_tester/trial.py
@@ -77,7 +77,7 @@
               .set_all_levels(log.L_DBG)
               .style_change(trace=True),
             log.FileLogTarget(run_dir.new_child(FILE_LOG_BRIEF))
-              .style_change(src=False, all_origins=False)
+              .style_change(src=False, all_origins_on_levels=(log.L_ERR, log.L_TRACEBACK))
             ]
         self.log('Trial start')
         self.log('Detailed log at', detailed_log)

-- 
To view, visit https://gerrit.osmocom.org/2731
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I0277782652548fa321f767da79b207d70678fad1
Gerrit-PatchSet: 2
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list