Skip to Content
Go: Building Web Applications
book

Go: Building Web Applications

by Nathan Kozyra, Mat Ryer
August 2016
Beginner to intermediate
665 pages
14h 11m
English
Packt Publishing
Content preview from Go: Building Web Applications

Logging to IO

So far we've been logging in to stdout, but you can utilize any io.Writer to ingest the log data. In fact, you can use multiple io.Writers if you want the output to be routed to more than one place.

Multiple loggers

Most mature applications will write to more than one log file to delineate between the various types of messages that need to be retained.

The most common use case for this is found in web server. They typically keep an access.log and an error.log file to allow the analysis of all successful requests; however, they also maintain separate logging of different types of messages.

In the following example, we modify our logging concept to include errors as well as warnings:

package main import ( "log" "os" ) var ( Warn *log.Logger ...
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.
Start your free trial

You might also like

Hands-On Full Stack Development with Go

Hands-On Full Stack Development with Go

Mina Andrawos

Publisher Resources

ISBN: 9781787123496