Back to all reviewers

Use appropriate log levels

kubeflow/kubeflow
Based on 3 comments
Go

Always match logging levels to the message's purpose and severity. Use log.Info for general information, log.Warn for warnings, and log.Error for error conditions. Avoid using fmt.Println for logging as it bypasses the logging framework's level-based filtering capabilities.

Logging Go

Reviewer Prompt

Always match logging levels to the message’s purpose and severity. Use log.Info for general information, log.Warn for warnings, and log.Error for error conditions. Avoid using fmt.Println for logging as it bypasses the logging framework’s level-based filtering capabilities.

Keep these guidelines in mind:

  • Start log messages with lowercase letters for consistency
  • Use the proper level that reflects the message’s importance
  • Provide descriptive content in error messages that explains what went wrong

Example of incorrect logging:

// Incorrect usage
fmt.Println("Present working directory is: %v", cwd)
log.Info("WARNING: Notebook container is not found, so could not update State of Notebook CR")

Example of correct logging:

// Correct usage
log.Info("setting up workload identity", "ClientId", azure.AzureIdentityClientId)
log.Error("could not find the notebook container", "notebook-name", instance.Name)

Following these practices helps with log filtering, improves troubleshooting, and creates a consistent logging experience throughout the codebase.

3
Comments Analyzed
Go
Primary Language
Logging
Category

Source Discussions