Home >Backend Development >Golang >Golang: Importance of planning how to display logs in high-use applications
Most of the time we don't spend the time necessary to correctly plan our application logs, which later causes us to rework, often unnecessary.
The well-planned and applied use of logs can, in addition to improving future analysis of a problem, significantly impact the performance of the application, especially for intense processes.
Thinking about exemplifying and demonstrating a little of this impact, here are two examples with their benchmark, respectively.
The first of a common way to "log" information in the code, but little information value, becomes just data:
benchmark_logs_test.go
Benchmark:
And the second with the structured log, only showing at the end the start and end times and the message.
benchmark_logs_enhancement_test.go
Benchmark:
Both examples have a loop of one hundred thousand indexes, which using goroutines, increments a variable.
When starting, the current time is captured, and when finished, the time it took is printed.
I'm using the logrus log library, as it has numerous interesting properties and functionality, such as structured logging.
You can clearly see the difference that a log that is not thought out correctly can cause in the performance of applications.
The above is the detailed content of Golang: Importance of planning how to display logs in high-use applications. For more information, please follow other related articles on the PHP Chinese website!