Skip to content

Conversation

@benjaminysmith
Copy link
Contributor

@benjaminysmith benjaminysmith commented Dec 15, 2020

Description

Add support for writing logs to file via param.

Changelog

  • Read params for logging file location (param "log_filename")
  • Pass this to logger as optional parameter
  • Pass logger directly to helper code instead of creating twice
  • Convert SirCAL logging to use this approach

Fixes

logger = get_structured_logger(__name__)
def get_logger():
params = read_params()
return get_structured_logger(__name__, filename = params.get("log_filename"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a convention to init the logger outside the main function as a constant (as opposed to putting it right after the read_params line in run_module)? I'm not super familiar with the best practice. Otherwise this PR looks good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked through a bunch of discussions on stack overflow, and there were advocates for both versions of this (and other versions too) so my reaction was that there is not a clear preference. I chose this one because it's slightly less work to pass around the logger to the individual functions (and I am also biased toward a java-ey approach).

Copy link
Contributor

@chinandrew chinandrew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit::shipit::shipit:

@krivard krivard merged commit 1bcb02c into cmu-delphi:main Dec 16, 2020
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.

Add structured logging to an indicator

3 participants