Skip to content

Commit

Permalink
Introduce LOGGING_OVERRIDE config var
Browse files Browse the repository at this point in the history
Co-Authored-By: Daniel Fangl <daniel.fangl@localstack.cloud>
  • Loading branch information
simonrw and dfangl committed May 13, 2024
1 parent 7917b4a commit 2474a6d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions localstack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ def in_docker():
LS_LOG = eval_log_type("LS_LOG")
DEBUG = is_env_true("DEBUG") or LS_LOG in TRACE_LOG_LEVELS

# allow setting custom log levels for individual loggers
LOGGING_OVERRIDE = os.environ.get("LOGGING_OVERRIDE", "{}")

# whether to enable debugpy
DEVELOP = is_env_true("DEVELOP")

Expand Down
18 changes: 18 additions & 0 deletions localstack/logging/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import sys
import warnings
Expand Down Expand Up @@ -78,6 +79,23 @@ def setup_logging_from_config():
for name, level in trace_internal_log_levels.items():
logging.getLogger(name).setLevel(level)

if raw_value := config.LOGGING_OVERRIDE:
try:
logging_overrides = json.loads(raw_value)
for logger, level_name in logging_overrides.items():
level = getattr(logging, level_name, None)
if not level:
raise RuntimeError(
f"Failed to configure logging overrides ({raw_value}): '{level_name}' is not a valid log level"
)
logging.getLogger(logger).setLevel(level)
except RuntimeError:
raise
except Exception as e:
raise RuntimeError(
f"Failed to configure logging overrides ({raw_value}): Malformed value. ({e})"
) from e


def create_default_handler(log_level: int):
log_handler = logging.StreamHandler(stream=sys.stderr)
Expand Down

0 comments on commit 2474a6d

Please sign in to comment.