-
Notifications
You must be signed in to change notification settings - Fork 17
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
add testing environment indicator to the logger #2042
Conversation
55cbe27
to
bbfcceb
Compare
bbfcceb
to
8ee933e
Compare
Mostly unrelated, but I would definitely prefer if we dealt with formatting stuff all in one PR. |
If in your case, test runs are 1. also run on prod, and 2. the logged info must be output to the same log file as real runs, then the If you want to, you can set up an elastic ingest pipeline to take advantage of elastic's log parsing by doing these: |
@minhkhul the point of this is to make it easier to evaluate the application's logging functionality in a sandboxed test environment; Elastic isnt part of the scope. I would lean towards removing the formatting changes from this PR, they distract from the core diffferences being applied and the rationale. |
def get_structured_logger(name=__name__, | ||
filename=None, | ||
log_exceptions=True): | ||
def get_structured_logger(name=__name__, filename=None, log_exceptions=True, is_real=True): |
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.
def get_structured_logger(name=__name__, filename=None, log_exceptions=True, is_real=True): | |
def get_structured_logger(name=__name__, filename=None, log_exceptions=True, *, test_mode=False): |
and then below:
cache_logger_on_first_use=not(test_mode),
This name (and inverted truth value) makes the purpose of the argument clearer, and the *
in the arguments list ensures its only ever triggered explicitly.
Thanks all for the comments, I eventually figured out a way around it without having to modify the functionality of |
Description
Following a recommendation from the structlog docs on testing. Needed so that I can actually test the log output from various warnings and errors in developing the Wastewater endpoint cmu-delphi/delphi-epidata#1513. Marked as a draft because I am still testing that this is all that's needed to be able to test the logger.
Changelog
get_structured_logger(name, filename, log_exceptions, *is_real=True*)
indicating whether to log as if in a testing environmentruff
decided were Correct. Can remove if they're a problem.