Standard library / log

log.Logger.Output()

Write a message with explicit source stack depth and return writer errors. Expected stdout: 'hello\n'.

Formal Syntax & Structure

go syntaxgo
func (l *Logger) Output(calldepth int, s string) error

Parameters & Attributes

NameTypeDescription
calldepthintNumber of stack frames to skip for source attribution.
sstringMessage text.

Return Value

error

Write a message with explicit source stack depth and return writer errors.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "log")
func check(e error) {  if e != nil {    panic(e)  }}
func main() {  var b bytes.Buffer  l := log.New(&b, "", 0)  check(l.Output(1, "hello"))  fmt.Print(b.String())}
Go Reference