Standard library / log

log.Logger.SetPrefix()

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

Formal Syntax & Structure

go syntaxgo
func (l *Logger) 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  l := log.New(&b, "", 0)  l.SetPrefix("app: ")  l.Print("hello")  fmt.Print(b.String())}
Go Reference