Logging #9: Observability via Logging

Problem Application monitoring has grown more complex in the days of SaaS and microservices. Solution Observability, which for me means the ability to analyze the system usually based on its metrics, traces and logs. Example From the 3 standard tools used to achieve an observable system, logging is the most powerful one. It is possible … Continue reading Logging #9: Observability via Logging

Logging #8: Logger Output

One of decisions that has to be made regarding logging is the choice of logging output. From my experience the decision largely depends on the application type. Please take notice that even though I have been creating apps in all of the listed types, it does not mean I am expert in any of those. … Continue reading Logging #8: Logger Output

Logging #7: Contextual Error Data Log Field

Problem Error logs miss contextual data, which are important to understand and troubleshoot the problem. Solution Add log fields containing contextual error data. If the error is raised deep in the call stack, then consider adding additional data to the returned error. Extract and add this contextual data to your structured logs when handling the … Continue reading Logging #7: Contextual Error Data Log Field

Logging #6: Correlation Log Field

Problem For concurrent applications it is hard to correlate multiple log entries which are emitted during the same request/pipeline. Solution Add contextual data to the log entries to enhance traceability. Example Let’s consider that we have following HTTP request handler that executes some background jobs (full code): func JobHandler(w http.ResponseWriter, r *http.Request) { go func() … Continue reading Logging #6: Correlation Log Field

Logging #5: Log Entry Builder

Problem Repetitive code when logging contextual data (like function's parameters, request's header). Solution Use Builder design pattern to create a log to be emitted. Example Let's consider that we have following HTTP request handler (full code): func OrderHandler(w http.ResponseWriter, r *http.Request) { var request struct { Product string `json:"product"` Quantity int `json:"quantity"` } if err … Continue reading Logging #5: Log Entry Builder

Logging #3: Structured Logging

Structured Logging, also known as Semantic Logging, is probably the most powerful logging pattern I know. Let's assume that our log is normally emitted as follows (code - uses Go standard library): 2009/11/10 23:00:00.000000 Hello, Robert! Structured log differs from "regular" plain-text log, that is formatted in a consisted way. Usually in some form of … Continue reading Logging #3: Structured Logging

Logrusutil = Contextual Logging + Error Fields for Logrus

In past two days I have created logrusutil which is a small utility library for logrus. Currently it contains two packages. I encourage to look at the GoDoc examples: logctxerrfield Feedback highly appreciated. You can write a comment here, create an issue on GitHub, write to me on LinkedIn/Facebook or even send an email. In … Continue reading Logrusutil = Contextual Logging + Error Fields for Logrus