From 61675b3f79b2270d9b3f60a197c43ce28636acee Mon Sep 17 00:00:00 2001 From: Rob Savoye Date: Wed, 20 Dec 2023 09:44:48 -0700 Subject: [PATCH] fix: Fix logging --- tm_admin/tmclient.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tm_admin/tmclient.py b/tm_admin/tmclient.py index a59afd6a..212557da 100755 --- a/tm_admin/tmclient.py +++ b/tm_admin/tmclient.py @@ -42,11 +42,11 @@ from tm_admin.projects.projects_proto import ProjectsMessage from tm_admin.organizations.organizations_proto import OrganizationsMessage from tm_admin.yamlfile import YamlFile -from tm_admin.commands import Notification, Request +# from tm_admin.commands import Notification, Request from tm_admin.types_tm import Command, Notification # Instantiate logger -log = logging.getLogger("tm-admin") +log = logging.getLogger(__name__) import tm_admin as tma rootdir = tma.__path__[0] @@ -137,13 +137,16 @@ def main(): # quit() # if verbose, dump to the terminal. + log_level = os.getenv("LOG_LEVEL", default="INFO") if args.verbose is not None: - log.setLevel(logging.DEBUG) - ch = logging.StreamHandler(sys.stdout) - ch.setLevel(logging.DEBUG) - formatter = logging.Formatter("%(threadName)10s - %(name)s - %(levelname)s - %(message)s") - ch.setFormatter(formatter) - log.addHandler(ch) + log_level = logging.DEBUG + + logging.basicConfig( + level=log_level, + format=("%(asctime)s.%(msecs)03d [%(levelname)s] " "%(name)s | %(funcName)s:%(lineno)d | %(message)s"), + datefmt="%y-%m-%d %H:%M:%S", + stream=sys.stdout, + ) tm = TMClient('test')