When I used logging from SL4j, where log4j is one of the implementation, I have a flexibility like below.
Log messages from our com.xyz.service package were logged to a separate file with a 30-day retention.
Log messages from our com.xyz.domain package with level ERROR were logged to another file with 90-day retention.
Log messages for all API requests were logged separately with a 72-hour retention.
Anything not matching one of those rules went to a default logfile with 7-day retention.
All of this configuration could be modified without changes to code, which was incredibly convenient.
Developers just logged events, and our DevOps team could reconfigure how those messages were handled.
For our current GraphQL project in Go lang, we want to have the same flexibility, with additioanl requirements below:
Log Levels. Need to have: DEBUG, INFO and ERROR level
Easy run-time configuration changes, including changing level filter and destination.
Easy run-time configuration changes possible from within the code.
Multiple back-ends including at least syslog, systemd, plain old text files, and some sort of structured text
Default value to allow one-line setup (plus import) when starting out.
Currently Go lang stdlib does not support the requirements above, so I have to use third party logging library that can achieve as close as to our requirements. Some of the code already used the stdlib logging package, so our candidate must be easy to replace the log statement everywhere
After some research, I found that LogRus (https://github.com/sirupsen/logrus) pretty close to our requirements. It’s also easy to replace stdlib log statement, since it’s completely api-compatible with the stdlib logger, so I just can replace my log imports everywhere with log “github.com/sirupsen/logrus” and now we have the flexibility of Logrus.
The other alternative is Zap from Uber (https://github.com/uber-go/zap), which claimed as a high performance log library. But we still choose Zap in the end for the above reason, and also Logrus has 5K more stars in Github compared to Zap.