DEV Community

Cover image for Fundamentals of Logging
Sankararaman K
Sankararaman K

Posted on

Fundamentals of Logging

Logging is the process of creating a trail of logs of a particular process or logic flow.

What is a log?

A log is a record of an event.

What types of events should be logged?

Events that should be logged depends on the use-case. Some use-cases where events should be logged are

  1. Failure logging
    • Log a trail of events that can lead to failure
    • Make sure these events don't create noice during successful execution
    • For example:
[Thu Mar 13 19:04:13 2014] [error] [client 10.1.10.50] File does not exist: /var/www/favicon.ico
Enter fullscreen mode Exit fullscreen mode
  1. Analytics logging
    • Log API endpoints to identify which APIs are frequently used
    • Log execution duration to track API response times
    • For example:
10.1.10.50 [Thu Mar 13 19:04:13 2014] 808840 “GET /inventory/item?itemId=234” 500”
Enter fullscreen mode Exit fullscreen mode

Other Considerations

  1. Logs should readable
  2. Logs should not be noisy
  3. Logs should be searchable and filterable
    • This can be done by assign a unique ID to every request and it can be used to filter all logs related to that ID

What other types of events do you log? What other parameters do you consider while defining a log? Feel free to add them in the comments!

Top comments (0)