Skip to content
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

Lazily evaluate log message parameters #690

Merged

Conversation

petedmarsh
Copy link
Contributor

@petedmarsh petedmarsh commented Sep 2, 2023

Logging like this:

logger.debug("Hello, %s" % name)

causes the message string to always be interpolated even if the message is not going to be logged.

Logging like this:

logger.debug("Hello, %s", name)

will mean the string is only ever interpolated if it will be logged.

In practice here this will make little difference if the log level is INFO
or above.

See:

https://docs.python.org/3/howto/logging.html#optimization https://stackoverflow.com/questions/4148790/lazy-logger-message-string-evaluation

Logging like this:

    logger.debug("Hello, %s" % name)

causes the message string to always be interpolated even if the
message is not going to be logged.

Logging like this:

    logger.debug("Hello, %s", name)

will mean the string is only ever interpolated if it will be logged.

In practice here this will make little difference if the log level
is INFO or above.

See:

https://docs.python.org/3/howto/logging.html#optimization
https://stackoverflow.com/questions/4148790/lazy-logger-message-string-evaluation
@petedmarsh
Copy link
Contributor Author

I realized I missed a bunch of cases using .format, have fixed those now.

@liampauling liampauling changed the base branch from master to release/2.5.0 September 11, 2023 14:15
@liampauling liampauling merged commit aa8edcd into betcode-org:release/2.5.0 Sep 11, 2023
5 checks passed
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