summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2020-04-09 04:03:14 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2020-04-09 04:42:45 +0700
commitec71203e79bf1b585ad56b80743759562898698f (patch)
tree5f4a7faae39124e4b6e8e4417c64464014fa83b6
parent67c49ba664f7d7d7f07986a20e6d6363a27e3fc4 (diff)
trx_toolkit/app_common: introduce auxiliary add_log_handler()
-rw-r--r--src/target/trx_toolkit/app_common.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/target/trx_toolkit/app_common.py b/src/target/trx_toolkit/app_common.py
index f2a47c54..8ee5054c 100644
--- a/src/target/trx_toolkit/app_common.py
+++ b/src/target/trx_toolkit/app_common.py
@@ -40,19 +40,25 @@ class ApplicationBase:
"This is free software: you are free to change and redistribute it.\n" \
"There is NO WARRANTY, to the extent permitted by law.\n")
+ def add_log_handler(self, lh, log_level, log_fmt):
+ lf = log.Formatter(log_fmt)
+ ll = log.getLevelName(log_level)
+
+ log.root.addHandler(lh)
+ lh.setFormatter(lf)
+ lh.setLevel(ll)
+
def app_init_logging(self, argv):
# Default logging handler (stderr)
- sh = log.StreamHandler()
- sh.setLevel(log.getLevelName(argv.log_level))
- sh.setFormatter(log.Formatter(argv.log_fmt))
- log.root.addHandler(sh)
+ lo = (argv.log_level, argv.log_fmt)
+ lh = log.StreamHandler()
+ self.add_log_handler(lh, *lo)
# Optional file handler
if argv.log_file_name is not None:
- fh = log.FileHandler(argv.log_file_name)
- fh.setLevel(log.getLevelName(argv.log_file_level))
- fh.setFormatter(log.Formatter(argv.log_file_fmt))
- log.root.addHandler(fh)
+ lo = (argv.log_file_level, argv.log_file_fmt)
+ lh = log.FileHandler(argv.log_file_name)
+ self.add_log_handler(lh, *lo)
# Set DEBUG for the root logger
log.root.setLevel(log.DEBUG)