Writing logs to multiple outputs in Go

The io.Writer interface is one of the most important interfaces in Go. We can take advantage of it to write logs to multiple places at the same time using the io.MultiWriter function.

For example, writing a log to the Standard Output (os.Stdout and a file os.File) is pretty straightforward.

f, _ := os.Create("log.txt")
defer f.Close()

// our writer
w := io.MultiWriter(os.Stdout, f)
logger := log.New(w, "MultiWriter loggger", log.LstdFlags)

Articles from blogs I follow around the net

Simpler encapsulation with immutability

A worked example. I've noticed that many software organizations struggle with encapsulation with 'bigger' problems. It may be understandable and easily applicable to define a NaturalNumber type or ensure that a minim…

via ploeh blog June 12, 2024

Update on our infrastructure plans

Now that Drew has provided an update on the general state of SourceHut, I would like to follow up with one focusing on our infrastructure. Much has happened under the hood, a lot has not happened, and plans come and go as reality changes its mind every now a…

via Blogs on Sourcehut June 12, 2024

OpenBSD extreme privacy setup

# Introduction This blog post explains how to configure an OpenBSD workstation with extreme privacy in mind. This is an attempt to turn OpenBSD into a Whonix or Tails alternative, although if you really need that level of privacy, use a system from this…

via Solene'% June 10, 2024

Generated by openring