Skip to content

Commit cec8fc5

Browse files
authored
Introduce LOG_LEVEL_OVERRIDES config var (#10808)
1 parent 79b46be commit cec8fc5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

localstack-core/localstack/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ def in_docker():
442442
# path to the lambda debug mode configuration file.
443443
LAMBDA_DEBUG_MODE_CONFIG_PATH = os.environ.get("LAMBDA_DEBUG_MODE_CONFIG_PATH")
444444

445+
# EXPERIMENTAL: allow setting custom log levels for individual loggers
446+
LOG_LEVEL_OVERRIDES = os.environ.get("LOG_LEVEL_OVERRIDES", "")
447+
445448
# whether to enable debugpy
446449
DEVELOP = is_env_true("DEVELOP")
447450

localstack-core/localstack/logging/setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from localstack import config, constants
66

7+
from ..utils.strings import key_value_pairs_to_dict
78
from .format import AddFormattedAttributes, DefaultFormatter
89

910
# The log levels for modules are evaluated incrementally for logging granularity,
@@ -81,6 +82,17 @@ def setup_logging_from_config():
8182
for name, level in trace_internal_log_levels.items():
8283
logging.getLogger(name).setLevel(level)
8384

85+
raw_logging_override = config.LOG_LEVEL_OVERRIDES
86+
if raw_logging_override:
87+
logging_overrides = key_value_pairs_to_dict(raw_logging_override)
88+
for logger, level_name in logging_overrides.items():
89+
level = getattr(logging, level_name, None)
90+
if not level:
91+
raise ValueError(
92+
f"Failed to configure logging overrides ({raw_logging_override}): '{level_name}' is not a valid log level"
93+
)
94+
logging.getLogger(logger).setLevel(level)
95+
8496

8597
def create_default_handler(log_level: int):
8698
log_handler = logging.StreamHandler(stream=sys.stderr)

0 commit comments

Comments
 (0)