Standard library / log

log.Logger.SetOutput()

Change the output destination. Expected stdout: 'hello\n'.

Formal Syntax & Structure

go syntaxgo
func (l *Logger) SetOutput(w io.Writer)

Parameters & Attributes

NameTypeDescription
wio.WriterWriter receiving log records.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "log")
func main() {  var b bytes.Buffer  l := log.New(&b, "", 0)  l.SetOutput(&b)  l.Print("hello")  fmt.Print(b.String())}
Go Reference