osmo-gsm-tester/src/osmo_gsm_tester
Neels Hofmeyr 1a7a3f0e43 fix and refactor logging: drop 'with', simplify
With the recent fix of the junit report related issues, another issue arose:
the 'with log.Origin' was changed to disallow __enter__ing an object twice to
fix problems, now still code would fail because it tries to do 'with' on the
same object twice. The only reason is to ensure that logging is associated with
a given object. Instead of complicating even more, implement differently.

Refactor logging to simplify use: drop the 'with Origin' style completely, and
instead use the python stack to determine which objects are created by which,
and which object to associate a log statement with.

The new way: we rely on the convention that each class instance has a local
'self' referencing the object instance. If we need to find an origin as a new
object's parent, or to associate a log message with, we traverse each stack
frame, fetching the first local 'self' object that is a log.Origin class
instance.

How to use:

Simply call log.log() anywhere, and it finds an Origin object to log for, from
the stack. Alternatively call self.log() for any Origin() object to skip the
lookup.

Create classes as child class of log.Origin and make sure to call
super().__init__(category, name). This constructor will magically find a parent
Origin on the stack.

When an exception happens, we first escalate the exception up through call
scopes to where ever it is handled by log.log_exn(). This then finds an Origin
object in the traceback's stack frames, no need to nest in 'with' scopes.

Hence the 'with log.Origin' now "happens implicitly", we can write pure natural
python code, no more hassles with scope ordering.

Furthermore, any frame can place additional logging information in a frame by
calling log.ctx(). This is automatically inserted in the ancestry associated
with a log statement / exception.

Change-Id: I5f9b53150f2bb6fa9d63ce27f0806f0ca6a45e90
2017-06-13 13:32:01 +02:00
..
templates osmo-msc: configure HLR address 2017-06-08 23:26:51 +02:00
__init__.py Re-License under GPLv3-or-later instead of AGPLv3-or-later 2017-06-03 14:23:51 +00:00
bts_model.py Re-License under GPLv3-or-later instead of AGPLv3-or-later 2017-06-03 14:23:51 +00:00
bts_osmotrx.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
bts_sysmo.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
config.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
event_loop.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
log.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
ofono_client.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
osmo_bsc.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
osmo_ctrl.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
osmo_hlr.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
osmo_mgcpgw.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
osmo_msc.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
osmo_nitb.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
pcap_recorder.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
process.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
report.py junit result: also write for aborted runs 2017-06-12 11:34:44 +00:00
resource.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
schema.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
sms.py Re-License under GPLv3-or-later instead of AGPLv3-or-later 2017-06-03 14:23:51 +00:00
suite.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
template.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
test.py test: Remove unused variable Failure 2017-06-12 12:07:46 +02:00
trial.py fix and refactor logging: drop 'with', simplify 2017-06-13 13:32:01 +02:00
util.py Re-License under GPLv3-or-later instead of AGPLv3-or-later 2017-06-03 14:23:51 +00:00