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

Add str.format variants of all log output methods #21

Merged
merged 4 commits into from Jan 20, 2017
Merged

Conversation

timj
Copy link
Member

@timj 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
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

@parejkoj parejkoj left a 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.
Copy link
Contributor

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.

Copy link
Member Author

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.

@timj timj merged commit 7e6699f into master Jan 20, 2017
@ktlim ktlim deleted the tickets/DM-8995 branch August 25, 2018 05:18
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.

None yet

3 participants