How it works...
The sirupsen/logrus and apex/log packages are both excellent structured loggers. Both provide hooks for either emitting to multiple events or to add extra fields to a log entry. It would be relatively simple, for example, to use the logrus hook or the apex custom handler to add line numbers to all of your logs as well as service names. Another use for a hook might include traceID to trace a request across different services.
While logrus splits the hook and the formatter, apex combines them. In addition, apex adds some convenience functions such as WithError to add an error field as well as tracing, both of which are demonstrated in the recipe. It's also relatively simple to adapt hooks from logrus into the apex handlers. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access