Logging is not the process of cutting down trees, but rather of writing out lines of text with a date and time connected to them, so you can see what your process is doing. Logs let you leave freeform messages as you go. Logs are often considered the scalable way of doing "print statement debugging". There are lots of similarities between the two. Print statements let you write messages out to stdout so you can see how your services is doing.

Logs let you add additional information to your print statements, and do so in a consistent manner. The standard library has a simple log library to start with, so you can turn the previous print statement into:

This will output:

Note the added current datetime and the lack of a need for a newline! So much better.

But logging's real power comes when you can add much more data to your log output using a more sophisticated logging library.

Each of these libraries has a different syntax, but they all let you do three extra exciting things:


This page is a preview of Reliable Webservers with Go

No discussions yet