Configuring multiple outputs
Why do we want to configure multiple outputs? Well, it is useful as, during development, it is easier to look at logs locally for troubleshooting purposes, but in production, it’s not possible to look at a log file, as everything will be inside the logging server.
We are going to write a thin layer of wrapper code that will wrap the golog
library; the code that we are going to look at is inside the chapter2/
directory, inside the logger/log.go
file. The benefit of having a wrapper code for the golog
library is to isolate the application for interfacing directly with the library; this will make it easy to swap to different logging libraries when and if required. The app configured the wrapper code by passing the parsed flag to the SetLoggingOutput(..)
function.
Build the application by running the following:
make build
Then, run it, passing the flag to true
as follows to write the log message to stdout
:
./sampledb -local=true
The...