Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 903 Bytes

4.3.md

File metadata and controls

37 lines (24 loc) · 903 Bytes

Logging

Concepts

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!")
}

Exercises

Tips

Further Reading

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.


prev -- up -- next