The standard library includes the logging package "log".
The log package includes the functions:
- Print, Printf, Println
- Fatal, Fatalf, Fatalln
- Panic, Panicf, Panicln
Where fatal calls os.Exit(1)
and panic calls panic()
.
Each log will appear on its own line with the date and time, and SetPrefix will add a prefix.
package main
import "log"
func main() {
log.SetPrefix("Info: ")
log.Print("Started")
log.Panic("Errored!")
}
The base log package is minimal, because no one logging solution will fit everyone's needs, be it log levels, speed, convenience, structured logs, etc. Find a logging solution that works for you. Some of the most popular include logrus and glog.