Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Turn logging on/off

  • Output
  • Discard
  • NullWriter
  • /dev/null
  • Stderr

By default the log module writes to the standard error (STDERR). We can turn off the logging by setting the Output channel to ioutil.Discard. We can turn on the logging again by setting the Output channel to os.Stderr.

package main

import (
	"io/ioutil"
	"log"
	"os"
)

func main() {
	log.Print("One")
	log.SetOutput(ioutil.Discard)
	log.Print("Two")
	log.SetOutput(os.Stderr)
	log.Print("Three")
}