Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Logging: Set Prefix

  • SetPrefix

  • Prefix

  • SetPrefix can set the prefix for each log message

  • Prefix returns the current prefix

package main

import (
	"log"
)

func main() {
	log.SetPrefix("Foo ")
	log.Print("First")
	log.Print("Second")
	log.SetPrefix("Bar ")
	log.Print("Third")
}
Foo 2020/04/10 09:33:40 First
Foo 2020/04/10 09:33:40 Second
Bar 2020/04/10 09:33:40 Third