diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2018-12-07 05:00:26 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2018-12-07 05:36:20 +0700 |
commit | 6bab6acee634fcd05a175428e1077ab00188829a (patch) | |
tree | c2cc2f8231efd29991f71b027323dbd5c10f7906 /src/target/trx_toolkit/fake_trx.py | |
parent | 72c8296bfe22eab749f9f29fe91f30d2588ded9c (diff) |
trx_toolkit: use generic logging module instead of print()
There are multiple advantages of using Python's logging module:
- advanced message formatting (file name, line number, etc.),
- multiple logging targets (e.g. stderr, file, socket),
- logging levels (e.g. DEBUG, INFO, ERROR),
- the pythonic way ;)
so, let's replace multiple print() calls by logging calls,
add use the following logging message format by default:
[%(levelname)s] %(filename)s:%(lineno)d %(message)s
Examples:
[INFO] ctrl_if_bts.py:57 Starting transceiver...
[DEBUG] clck_gen.py:87 IND CLOCK 26826
[DEBUG] ctrl_if_bts.py:71 Recv POWEROFF cmd
[INFO] ctrl_if_bts.py:73 Stopping transceiver...
[INFO] fake_trx.py:127 Shutting down...
Please note that there is no way to filter messages by logging
level yet. This is to be introduced soon, together with argparse.
Change-Id: I7fcafabafe8323b58990997a47afdd48b6d1f357
Diffstat (limited to 'src/target/trx_toolkit/fake_trx.py')
-rwxr-xr-x | src/target/trx_toolkit/fake_trx.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/target/trx_toolkit/fake_trx.py b/src/target/trx_toolkit/fake_trx.py index d99186b3..ced12381 100755 --- a/src/target/trx_toolkit/fake_trx.py +++ b/src/target/trx_toolkit/fake_trx.py @@ -25,6 +25,7 @@ from copyright import print_copyright CR_HOLDERS = [("2017-2018", "Vadim Yanitskiy <axilirator@gmail.com>")] +import logging as log import signal import getopt import select @@ -53,6 +54,10 @@ class Application: # Set up signal handlers signal.signal(signal.SIGINT, self.sig_handler) + # Configure logging + log.basicConfig(level = log.DEBUG, + format = "[%(levelname)s] %(filename)s:%(lineno)d %(message)s") + def run(self): # Init TRX CTRL interface for BTS self.bts_ctrl = CTRLInterfaceBTS(self.bts_addr, self.bts_base_port + 101, @@ -90,7 +95,7 @@ class Application: self.clck_gen = CLCKGen([self.bts_clck]) self.bts_ctrl.clck_gen = self.clck_gen - print("[i] Init complete") + log.info("Init complete") # Enter main loop while True: @@ -119,7 +124,7 @@ class Application: self.bb_ctrl.handle_rx(data.decode(), addr) def shutdown(self): - print("[i] Shutting down...") + log.info("Shutting down...") # Stop clock generator self.clck_gen.stop() @@ -198,7 +203,7 @@ class Application: sys.exit(2) def sig_handler(self, signum, frame): - print("Signal %d received" % signum) + log.info("Signal %d received" % signum) if signum is signal.SIGINT: self.shutdown() sys.exit(0) |