Awesome Logging in Go With Logrus
Which I enjoyed using in several projects so far

There are many logging libraries for Go on Github. However, I really like to use logrus.
It’s a logging library that provides all features that I need and offers helpful features like coloured output, full or short timestamp printing and the functionality to log additional fields.
Although it’s currently in maintenance mode (to avoid breaking changes in future versions), security patches and bug fixes are still applied. Looking at the GitHub repo, you can see that a lot of effort (e.g. in terms of commits) was put into this. Let’s dive into some configuration and usage examples.
Log Levels
Logrus offers different log levels, i.e. “panic”, “fatal”, “error”, “warning”, “info”, “debug”, “trace”. As usual, these levels are ordered and calls to lower levels (e.g. trace) are not logged if the level is set to info. The levels can be set via SetLevel
. My favourite way to import logrus is to name it to log
, which makes logging more convenient.
Formatting
Logrus provides different formatters, like: TextFormatter
and JSONFormatter
. These print different outputs and can be configured with a set of options. My favourite configuration is using TextFormatter
with colours enabled and full timestamp support.
Logging
Each log level is implemented with two separate functions in logrus, for level info they are called Info
and Infof
.
The first one is used to log a simple string, the second one accepts a string containing formats followed by a variadic list of interface arguments.
Furthermore, logrus
provides a WithField
function to add fields to a logger, which can be used to generate a logger with context
Despite having a lot of competition, the logrus library for logging in Go served well for me in several projects and with knowing the tricks and configurations, it really provides a nice logging experience.
So I would definitely recommend it to anyone who is in search of a logging library in Go.