Skip to content

Commit

Permalink
Provide lgging level in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
George V. Kouryachy (Fr. Br. George) committed Oct 20, 2023
1 parent f4aa7fa commit b65781c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions hworker/control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import atexit
import cmd
import io
import logging
import re
import secrets
import shlex
Expand Down Expand Up @@ -230,6 +231,28 @@ def complete_check(self, text, line, begidx, endidx):
objnames = ("all", "new")
return self.filtertext(objnames, text)

def do_logging(self, arg):
"""Set console log level"""
objnames = logging.getLevelNamesMapping()
logger = logging.getLogger()
handler = [hand for hand in logger.handlers if isinstance(hand, logging.StreamHandler)][0]
if arg:
if arg in objnames:
handler.setLevel(arg)
else:
print(logging.getLevelName(handler.level))

def complete_logging(self, text, line, begidx, endidx):
d = logging.getLevelNamesMapping()
objnames = sorted(d, key=lambda x: d[x])
return self.filtertext(objnames, text)

def help_logging(self):
res = "Set console log level\n\n" + ", ".join(
f"{key}={val}" for key, val in logging.getLevelNamesMapping().items()
)
print(res, file=sys.stderr)

def do_publish(self, arg):
"""Start publisher"""
# TODO check if is anything to publish
Expand Down

0 comments on commit b65781c

Please sign in to comment.