Skip to content

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lizard-boy
Copy link

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.

Copy link

@greptile-apps greptile-apps bot left a 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 in localstack/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 in localstack/utils/collections.py to handle override parsing
  • Added unit tests for parse_key_value_pairs in tests/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

Comment on lines +85 to +92
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)
Copy link

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

Comment on lines +93 to +98
except RuntimeError:
raise
except Exception as e:
raise RuntimeError(
f"Failed to configure logging overrides ({raw_logging_override})"
) from e
Copy link

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

Comment on lines +547 to +549
items = pair.split("=")
if len(items) != 2:
raise ValueError(f"invalid key/value pair: '{pair}'")
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants