Standard library / log

log.SetPrefix()

Set the text prefix for subsequent messages. Expected stdout: 'app: hello\n'.

Formal Syntax & Structure

go syntaxgo
func SetPrefix(prefix string)

Parameters & Attributes

NameTypeDescription
prefixstringText prepended to each log entry.

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.SetPrefix("app: ")  log.Print("hello")  fmt.Print(b.String())}
Go Reference