Skip to content

Instantly share code, notes, and snippets.

@kjivan
Last active July 3, 2024 19:52
Show Gist options
  • Save kjivan/38721324dca598ac05ddb92ce5545bee to your computer and use it in GitHub Desktop.
Save kjivan/38721324dca598ac05ddb92ce5545bee to your computer and use it in GitHub Desktop.
Logging Best Practices

Logging Best Practices

This assumes you have a fast memory logging system.

Use 4 logging levels

  • error - Log critical system errors only (not user errors)
  • warn - Log things that are potential errors or can become errors
  • info(default) - Logs info about events in the system
  • debug - Log more detailed info about debugging

Application Logging

Request Logging

  • Log every request from any API(REST/Kafka/Queues/etc) at info level
    • eg request to create a person in your system
  • Log all useful unique identifier(Database IDs/kafka offsets)
  • Don't log any sensitive data unless approved
  • Consider http logging and don't add redundant logging
    • If http logging captures everything to debug any issue don't add anything

Event Logging

  • Log the outcome of every request at info level
    • eg if a resource was created/merged/scheduled/completed/not completed
    • Identifiers should already be logged when the request came in, but add them if needed
  • Log every cron job that gets triggered
    • Log all useful identifiers and the task being done
    • Log the outcome of the cron job
      • eg records processed

Detailed/Debug logging

  • Optional detailed/debug logging should be at debug level
    • eg request/response payloads/every step of a workflow

Related

Error Handling Best Practices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment