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 str.format variants of all log output methods #21
Conversation
timj
commented
Jan 19, 2017
- String formatting is only done on demand.
- Supports keyword args for format()
- String formatting is only done on demand. - Supports keyword args for format()
if use_format: | ||
msg=fmt.format(*args, **kwargs) if args or kwargs else fmt | ||
else: | ||
msg=fmt % args if args else fmt |
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.
Add couple more spaces for indent here and 2 lines above
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.
Yes. I noticed there are linter problems with the code (should be spaces around the equals signs). I was worried that fixing them would confuse the review. I'll do a linting pass as a separate commit.
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.
One doc wording comment.
@@ -135,6 +135,15 @@ In Python, the following logging functions are available in the `lsst.log` modul | |||
- `error(fmt, *args)` Log a message of level `ERROR` with format string '''`fmt`''' and corresponding arguments '''`*args`''' to the default logger. | |||
- `fatal(fmt, *args)` Log a message of level `FATAL` with format string '''`fmt`''' and corresponding arguments '''`*args`''' to the default logger. | |||
|
|||
Additionally, Python has variants of the above functions, with a trailing `f` in the name, supporting the Python string `format()` syntax. The use of `*args` and `**kwargs` is recommended over the use of the `format()` method directly so that formatting of log messages that do not meet the level threshold can be avoided. |
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.
I'd reword the end of that to:
is recommended over the use of calling `format()` method on the string directly, to avoid unnecessarily formatting log messages that do not meet the level threshold.
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.
I actually copied that exact sentence from a few lines above so I was keeping it in the same style.