mirror of
https://github.com/pommi/python-itho-wpu.git
synced 2024-11-21 13:52:15 +01:00
feat(itho-wpu): add timestamp argument to make it optional
By default don't output timestamps for each line. Provide command line argument --timestamp to enable it again.
This commit is contained in:
parent
57954bafb4
commit
236d5c34fc
@ -13,11 +13,10 @@ import json
|
|||||||
import db
|
import db
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
consolelogformatter = logging.Formatter("%(asctime)-15s %(levelname)s: %(message)s")
|
|
||||||
logger = logging.getLogger('stdout')
|
logger = logging.getLogger('stdout')
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
stdout_log_handler = logging.StreamHandler(sys.stdout)
|
stdout_log_handler = logging.StreamHandler(sys.stdout)
|
||||||
stdout_log_handler.setFormatter(consolelogformatter)
|
stdout_log_handler.setFormatter(logging.Formatter("%(message)s"))
|
||||||
logger.addHandler(stdout_log_handler)
|
logger.addHandler(stdout_log_handler)
|
||||||
|
|
||||||
|
|
||||||
@ -60,6 +59,7 @@ def parse_args():
|
|||||||
parser.add_argument('--loglevel', nargs='?',
|
parser.add_argument('--loglevel', nargs='?',
|
||||||
choices=["debug", "info", "warning", "error", "critical"],
|
choices=["debug", "info", "warning", "error", "critical"],
|
||||||
help="Loglevel")
|
help="Loglevel")
|
||||||
|
parser.add_argument('--timestamp', action='store_true', help="Show timestamp in output")
|
||||||
parser.add_argument('--master-only', action='store_true', help="Only run I2C master")
|
parser.add_argument('--master-only', action='store_true', help="Only run I2C master")
|
||||||
parser.add_argument('--slave-only', action='store_true', help="Only run I2C slave")
|
parser.add_argument('--slave-only', action='store_true', help="Only run I2C slave")
|
||||||
parser.add_argument('--slave-timeout', nargs='?', type=int, default=60,
|
parser.add_argument('--slave-timeout', nargs='?', type=int, default=60,
|
||||||
@ -379,6 +379,11 @@ if __name__ == "__main__":
|
|||||||
if args.loglevel:
|
if args.loglevel:
|
||||||
logger.setLevel(args.loglevel.upper())
|
logger.setLevel(args.loglevel.upper())
|
||||||
|
|
||||||
|
if args.timestamp:
|
||||||
|
stdout_log_handler.setFormatter(
|
||||||
|
logging.Formatter("%(asctime)-15s %(levelname)s: %(message)s")
|
||||||
|
)
|
||||||
|
|
||||||
wpu = IthoWPU(args.master_only, args.slave_only, args.slave_timeout, args.no_cache)
|
wpu = IthoWPU(args.master_only, args.slave_only, args.slave_timeout, args.no_cache)
|
||||||
response = wpu.get(args.action)
|
response = wpu.get(args.action)
|
||||||
if response is not None:
|
if response is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user