Standard library / log
log.SetOutput()
Change the output destination. Expected stdout: 'hello\n'.
Formal Syntax & Structure
go syntaxgo
func SetOutput(w io.Writer)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| w | io.Writer | Writer receiving log records. |
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "log")
func main() { var b bytes.Buffer log.SetOutput(&b) log.SetFlags(0) log.SetPrefix("") log.SetOutput(&b) log.Print("hello") fmt.Print(b.String())}