From: Jakob Cornell Date: Wed, 14 Sep 2022 04:56:09 +0000 (-0500) Subject: Make stdout logging threshold configurable X-Git-Tag: strikebot-0.0.7~25 X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=40d364dabb3fcd2c43c7d10f35c5511837b3481a;p=counting.git Make stdout logging threshold configurable --- diff --git a/strikebot/docs/sample_config.ini b/strikebot/docs/sample_config.ini index 28e510e..7efebdd 100644 --- a/strikebot/docs/sample_config.ini +++ b/strikebot/docs/sample_config.ini @@ -9,6 +9,11 @@ auth IDs = 13 15 bot user = count_better enforcing = true + +# log messages at or above this severity to standard out; level names and numbers are supported (optional, default +# WARNING); see https://docs.python.org/3/library/logging.html#levels +log level = WARNING + thread ID = abc123 diff --git a/strikebot/src/strikebot/__main__.py b/strikebot/src/strikebot/__main__.py index ac490b6..e725eeb 100644 --- a/strikebot/src/strikebot/__main__.py +++ b/strikebot/src/strikebot/__main__.py @@ -121,6 +121,13 @@ api_pool_error_window = dt.timedelta(seconds = main_cfg.getfloat("API pool error auth_ids = set(map(int, main_cfg["auth IDs"].split())) bot_user = main_cfg["bot user"] enforcing = main_cfg.getboolean("enforcing") + +raw_log_level = main_cfg.get("log level", "WARNING") +try: + log_level = int(raw_log_level) +except ValueError: + log_level = raw_log_level + reorder_buffer_time = dt.timedelta(seconds = main_cfg.getfloat("reorder buffer time")) request_queue_limit = main_cfg.getint("request queue limit") thread_id = main_cfg["thread ID"] @@ -138,14 +145,14 @@ db_connect_params = {k: getters.get(k, db_cfg.get)(k) for k in db_cfg} logger = getLogger(__package__) -logger.setLevel(logging.DEBUG) +logger.setLevel(logging.NOTSET - 1) # NOTSET means inherit from parent; we use handlers to filter handler = StreamHandler(stdout) -handler.setLevel(logging.WARNING) +handler.setLevel(log_level) handler.setFormatter(logging.Formatter("{asctime:23}: {name:17} {levelname:8}: {message}", style = "{")) logger.addHandler(handler) -if _DEBUG_LOG_PATH: +if _DEBUG_LOG_PATH: # TODO remove this ad hoc setup debug_handler = FileHandler(_DEBUG_LOG_PATH, mode = "w") debug_handler.setLevel(logging.DEBUG) debug_handler.setFormatter(logging.Formatter("{asctime:23}: {name:17} {levelname:8}: {message}", style = "{"))