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, in order to trace a request across different services.

While logrus splits the hook and the formatter, apex combines them. In addition to this, apex adds some convenience functions such as WithError to add an error field as well as tracing, both of which are demonstrated in this recipe. It's also relatively simple to adapt hooks from logrus to the apex handlers. For both solutions, it would be a simple change to convert to JSON formatting, instead of ANSI-colored text.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.72.224