betcode-org / flumine

flūmine - Betting trading framework
MIT License
177 stars 60 forks source link

Lazily evaluate log message parameters #690

Closed petedmarsh closed 1 year ago

petedmarsh commented 1 year ago

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 commented 1 year ago

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