-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce LOGGING_OVERRIDE config var #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f443788
7909941
356ad77
cce4b2d
aa4269c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
from localstack import config, constants | ||
|
||
from ..utils.collections import parse_key_value_pairs | ||
from .format import AddFormattedAttributes, DefaultFormatter | ||
|
||
# The log levels for modules are evaluated incrementally for logging granularity, | ||
|
@@ -78,6 +79,24 @@ def setup_logging_from_config(): | |
for name, level in trace_internal_log_levels.items(): | ||
logging.getLogger(name).setLevel(level) | ||
|
||
raw_logging_override = config.LOGGING_OVERRIDE | ||
if raw_logging_override: | ||
try: | ||
logging_overrides = parse_key_value_pairs(raw_logging_override) | ||
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_logging_override}): '{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_logging_override})" | ||
) from e | ||
Comment on lines
+93
to
+98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Catch specific exceptions instead of using a broad except clause |
||
|
||
|
||
def create_default_handler(log_level: int): | ||
log_handler = logging.StreamHandler(stream=sys.stderr) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,3 +533,24 @@ def is_comma_delimited_list(string: str, item_regex: Optional[str] = None) -> bo | |
if pattern.match(string) is None: | ||
return False | ||
return True | ||
|
||
|
||
def parse_key_value_pairs(raw_text: str) -> dict: | ||
""" | ||
Parse a series of key-value pairs, in an environment variable format into a dictionary | ||
|
||
>>> input = "a=b,c=d" | ||
>>> assert parse_key_value_pairs(input) == {"a": "b", "c": "d"} | ||
""" | ||
result = {} | ||
for pair in raw_text.split(","): | ||
items = pair.split("=") | ||
if len(items) != 2: | ||
raise ValueError(f"invalid key/value pair: '{pair}'") | ||
Comment on lines
+547
to
+549
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using a more robust parsing method, such as |
||
raw_key, raw_value = items[0].strip(), items[1].strip() | ||
if not raw_key: | ||
raise ValueError(f"missing key: '{pair}'") | ||
if not raw_value: | ||
raise ValueError(f"missing value: '{pair}'") | ||
result[raw_key] = raw_value | ||
return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Potential performance impact if many overrides are specified. Consider caching results