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

Introduces convenient logging functions for usage in loops: #264

Closed
wants to merge 1 commit into from

Conversation

copybara-service[bot]
Copy link

Introduces convenient logging functions for usage in loops:

The functions with the postfix _once only log when they are called for the first time. This is useful when used inside loops while the arguments to be logged do not change. The current alternatives (logging.info, logging.warning, etc.) can load the log too heavily here.

  • log_once(level, msg, *args) Logs only the first call. (Forwards to log_first_n)
  • debug_once(msg, *args) forwards to log_once.
  • info_once(msg, *args) forwards to log_once.
  • warning_once(msg, *args) forwards to log_once.
  • error_once(msg, *args) forwards to log_once.
  • fatal_once(msg, *args) forwards to log_once.

The functions with the postfix `_once` only log when they are called for the first time. This is useful when used inside loops while the arguments to be logged do not change. The current alternatives (`logging.info`, `logging.warning`, etc.) can load the log too heavily here.

* `log_once(level, msg, *args)` Logs only the first call. (Forwards to `log_first_n`)
* `debug_once(msg, *args)` forwards to `log_once`.
* `info_once(msg, *args)` forwards to `log_once`.
* `warning_once(msg, *args)` forwards to `log_once`.
* `error_once(msg, *args)` forwards to `log_once`.
* `fatal_once(msg, *args)` forwards to `log_once`.

PiperOrigin-RevId: 535561745
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.

1 participant