Logging Best Practices
Use these guidelines to write log output that is useful when something goes wrong (or just to confirm that things are working as expected). Treat them as a checklist when adding or reviewing logging in your calculation modules.
Use Logging
Actually put log entries in your module code. Don't be tempted to ignore this principle or "do it later". Even if you think a log message isn't important, it may be crucial for diagnosing an issue in the future.
Sensitive Information
Avoid logging sensitive information, such as passwords or personal data.
Appropriate Log Levels
Use log levels appropriately to ensure that critical information is not lost in a sea of less important log entries. The Log Levels section provides guidelines on how to use log levels effectively.
Structured Logging
Learn how to use structured logging effectively. Structured logging can greatly enhance the usefulness of your logs for diagnosing issues and understanding application behavior.
Log Codes
Use unique log codes for each log message. Log codes are not enforced when writing log entries in your module, but they will improve the organization and accessibility of your logs. A simple search for a log code can highlight all instances of that specific log message, making it easier to find and analyze related log entries.
Review Log Entries
At every code change, review the log entries that it produces to ensure they remain relevant and useful. Misleading stale log messages can be worse than no log messages at all, as they can lead to confusion and misdiagnosis of issues. Regularly reviewing and updating your log entries will help maintain the quality and usefulness of your logs over time.