-
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?
Conversation
Co-Authored-By: Daniel Fangl <[email protected]>
Co-authored-by: Dominik Schubert <[email protected]>
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.
PR Summary
Introduced a new experimental configuration variable 'LOGGING_OVERRIDE' to allow setting custom log levels for individual loggers, primarily for debugging purposes.
- Added
LOGGING_OVERRIDE
inlocalstack/config.py
for fine-grained logger control - Implemented parsing and application of logging overrides in
localstack/logging/setup.py
- Created
parse_key_value_pairs
function inlocalstack/utils/collections.py
to handle override parsing - Added unit tests for
parse_key_value_pairs
intests/unit/utils/test_collections.py
- Feature is not intended for general use documentation, as it's a temporary solution
4 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings
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) |
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
except RuntimeError: | ||
raise | ||
except Exception as e: | ||
raise RuntimeError( | ||
f"Failed to configure logging overrides ({raw_logging_override})" | ||
) from e |
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: Catch specific exceptions instead of using a broad except clause
items = pair.split("=") | ||
if len(items) != 2: | ||
raise ValueError(f"invalid key/value pair: '{pair}'") |
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: Consider using a more robust parsing method, such as shlex.split()
, to handle cases where values might contain commas
Motivation
While debugging DNS issues, we found the need to add additional logging to help debugging, but only for a specific module. The DNS resolution process is too noisy to use current debug logs.
See localstack#10809 for an application of this new config feature.
Changes
@dfangl suggested we support a per-logger override for the log level. This would mean that if we are interested in a specific logger (or can disable some logs), we can specify this in a structured environment variable.
Note: we are planning on re-working the logging overall, so this functionality should only be used in specific cases, to enable more detailed logs for specific aspects of LocalStack's internals, and not documented.