Make stdout logging threshold configurable
authorJakob Cornell <jakob+gpg@jcornell.net>
Wed, 14 Sep 2022 04:56:09 +0000 (23:56 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Wed, 14 Sep 2022 05:15:59 +0000 (00:15 -0500)
strikebot/docs/sample_config.ini
strikebot/src/strikebot/__main__.py

index 28e510e54497f38b680613bea9c9f53bbc979c1b..7efebdd32e81ecc882f52144255786a0c9bc3281 100644 (file)
@@ -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
 
 
index ac490b6f901e10cfe6e063a604064473a53be486..e725eeb94f4d49a85183a9901acbf23636a7f077 100644 (file)
@@ -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 = "{"))