🧬 Logging

Bhautik Chudasama
2 min readNov 12, 2022

Logging events help us to get insights, and take effective decision.

There are two types of events in logging:

Audit Event:

Typically records of an action, state that needs to be retained to provide a formal record that may be required at some future point to resolve the issue of compliance.

Log Event:

  • These record “something happened”, and help us to get technical reasons.

Log levels, and severities

Level or severities defines the impact of log event.

Trace

Tracking the execution, What method is executing.

Debug

Primary log visible only in development mode / debugging mode.

Info

Information log that is used in an everyday operational environment.

Warn

When things are not working as expected, and there is a risk of error, but the system can continue to execute.

Error

Something intervention happens, and the system graceful shutdown.

Fatal

Something intervention happens, and the system terminates immediately without graceful shutdown.

Best Practices

  • Choose the word carefully, and make your synonym have not double meaning (Most of the time happens to me).
  • Ensure log message structure as possible.
  • Make sure you’re not logging sensitive data.

Context helps to understand the log:

  • What — What is being reported, an error or just a trace?
  • When — The date and time. This is easy if you’re using some form of logging framework.
  • Where — Where in the code and where in the infrastructure is the log event's source?
  • Why — When it comes to log levels of info and higher, why we provide the information is essential. Is there a problem about to occur, or are we reporting something you want to track, like a login action?
  • Who — Who triggered the action? Whose data could be impacted?

12 Factor principles:

Treat logs as an event stream, Process must write logs in stdoutstream. So if you write log in a file then there will be difficult search and aggregate. Instead of written in a log file, it must be written to stdout so the log is visible during the development in the terminal, and for staging and production, it will be captured by the execution environment, collated together with all other streams from the app, and routed to one or more final destinations for viewing and long-term archival.

There the lots of observability things that we will cover later on.

Thank you for reading my post. Originally written at https://bhautik.super.site.

--

--

Bhautik Chudasama

Just Bhautik with Software Engineer | Software Architect | DevOps | SRE http://rmtsbus.in and self. Enjoy the web.