Skip to content

Commit c595e78

Browse files
committed
fix: Avoid passing empty strings as log levels
Fix bug that resulted in empty strings being passed as log levels when deploying through docker compose. More specifically, when the `LOG_LEVEL` environment variables weren't set, compose would default to creating them as empty strings. Due to the fact that the variables existed, `os.getenv` would use these empty strings instead of the default values specified in the code (i.e. `logging.INFO`). Signed-off-by: Phoevos Kalemkeris <[email protected]>
1 parent 037a430 commit c595e78

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

cogstack_model_gateway/common/logging.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import logging
22
import os
33

4+
COMMON_LOG_LEVEL_VAR = "CMG_COMMON_LOG_LEVEL"
5+
GATEWAY_LOG_LEVEL_VAR = "CMG_GATEWAY_LOG_LEVEL"
6+
RIPPER_LOG_LEVEL_VAR = "CMG_RIPPER_LOG_LEVEL"
7+
SCHEDULER_LOG_LEVEL_VAR = "CMG_SCHEDULER_LOG_LEVEL"
8+
49

510
def configure_logging():
611
"""Configure logging for the CogStack Model Gateway packages.
@@ -16,7 +21,7 @@ def configure_logging():
1621
handler.setFormatter(logging.Formatter("%(levelname)s:%(name)s:%(message)s"))
1722
parent_logger.addHandler(handler)
1823

19-
logging.getLogger("cmg.common").setLevel(os.getenv("CMG_COMMON_LOG_LEVEL", logging.INFO))
20-
logging.getLogger("cmg.gateway").setLevel(os.getenv("CMG_GATEWAY_LOG_LEVEL", logging.INFO))
21-
logging.getLogger("cmg.ripper").setLevel(os.getenv("CMG_RIPPER_LOG_LEVEL", logging.INFO))
22-
logging.getLogger("cmg.scheduler").setLevel(os.getenv("CMG_SCHEDULER_LOG_LEVEL", logging.INFO))
24+
logging.getLogger("cmg.common").setLevel(os.getenv(COMMON_LOG_LEVEL_VAR) or logging.INFO)
25+
logging.getLogger("cmg.gateway").setLevel(os.getenv(GATEWAY_LOG_LEVEL_VAR) or logging.INFO)
26+
logging.getLogger("cmg.ripper").setLevel(os.getenv(RIPPER_LOG_LEVEL_VAR) or logging.INFO)
27+
logging.getLogger("cmg.scheduler").setLevel(os.getenv(SCHEDULER_LOG_LEVEL_VAR) or logging.INFO)

0 commit comments

Comments
 (0)