Back to all reviewers

Choose appropriate logging functions

cloudflare/workerd
Based on 2 comments
Other

Select the correct logging function based on frequency, severity, and destination to avoid log spam and ensure proper routing. Use LOG_ONCE or LOG_PERIODICALLY for repeated warnings that could spam logs, KJ_LOG(ERROR) for general error logging, and LOG_EXCEPTION only for exceptions intended for Sentry monitoring.

Logging Other

Reviewer Prompt

Select the correct logging function based on frequency, severity, and destination to avoid log spam and ensure proper routing. Use LOG_ONCE or LOG_PERIODICALLY for repeated warnings that could spam logs, KJ_LOG(ERROR) for general error logging, and LOG_EXCEPTION only for exceptions intended for Sentry monitoring.

For repeated warnings that could spam logs:

// Instead of:
KJ_LOG(WARNING, "jurisdiction restrictions have no affect in workerd", jurisdiction);

// Use:
KJ_LOG_ONCE(WARNING, "jurisdiction restrictions have no affect in workerd", jurisdiction);
// or
KJ_LOG_PERIODICALLY(WARNING, "jurisdiction restrictions have no affect in workerd", jurisdiction);

For exception logging, choose based on destination:

// For general error logging:
KJ_LOG(ERROR, "test failed with exception", exception);

// Only for Sentry-bound exceptions:
LOG_EXCEPTION("test", exception);

This prevents log flooding, ensures appropriate log routing, and maintains clean, actionable log output across different environments.

2
Comments Analyzed
Other
Primary Language
Logging
Category

Source Discussions