Turn logging on/off


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.

examples/logging-off/logging_off.go
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")
}