Select the appropriate log level based on operational significance and ensure messages are clear, accurate, and formatted for human readability: 1. **ERROR**: Use for failures requiring immediate attention
Select the appropriate log level based on operational significance and ensure messages are clear, accurate, and formatted for human readability:
Consider the frequency and volume of log entries when selecting levels. High-frequency operations should use lower log levels (DEBUG) to avoid log pollution and performance degradation.
Format log messages for runtime readability with variables logically positioned:
// Bad - Poor readability in runtime logs
warn!(
"could not create image layers due to {}; this is not critical because the requested image LSN is below the GC curoff",
err
);
// Good - Clear and readable at runtime
warn!(
"failed to create image layers but lsn is <= gc_cutoff, therefore this can happen: lsn={lsn} gc_cutoff={gc_cutoff}: {err}",
);
Ensure log messages accurately describe the operation being performed and provide meaningful context. Avoid logging routine operations in tight loops, especially at higher log levels.
Enter the URL of a public GitHub repository