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
Tag: 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 #4: Log Levels
Most logging libraries provide a possibility to set the level from which the logs are emitted. Moreover, the log level is usually an out-of-the-box field in logs. Below I describe my rules that I use when choosing a log level. Fatal (or Critical)Serious error. The application is going to close.ErrorApplication error. However the application can … Continue reading Logging #4: Log Levels
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
Logging #2: It Depends
Before going into specific application logging techniques I want to stress most (if not all) of them can cause some trade-off. Never forget that for everything in software "It Depends". Adding a logging library or technique requires others to get familiar with it. The log package from Go standard library may be good enough. I … Continue reading Logging #2: It Depends
Logging #1: Demo Application
This is the first installment of the blog post series describing application logging. The posts are going to be short. I use Go, but most of the concepts is should be language agnostic. I will try to list good supplemental references. First, I want to present a demo application go-structured-logging-demo, which I will use to … Continue reading Logging #1: Demo Application
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