Skip to content

Instantly share code, notes, and snippets.

@iyashjayesh
Last active June 30, 2022 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iyashjayesh/6081706eb212cdb9dcf3922c49d3e57d to your computer and use it in GitHub Desktop.
Save iyashjayesh/6081706eb212cdb9dcf3922c49d3e57d to your computer and use it in GitHub Desktop.
Golang Logrus Simple Implementation
package main
import (
"github.com/sirupsen/logrus"
)
func main() {
var log = logrus.New()
log.SetFormatter(&logrus.JSONFormatter{
// DisableTimestamp: false, // Default: false
// DisableSorting: false, // sort the fields in the order of the keys
// PrettyPrint: true, // for debugging
TimestampFormat: "2006-01-02 15:04:05",
})
log.SetLevel(logrus.DebugLevel) // if we comment this line, the default log level is info level
log.SetReportCaller(true) //use setReportCaller to set the line number of the log entry.
log.WithFields(logrus.Fields{
"animal": "walrus",
"size": 10,
}).Info("A group of walrus emerges from the ocean")
log.Info("Info log example")
log.Warn("Warn log example")
log.Error("Error log example")
log.Debug("Debug log example")
// log.Panic("Panic log example")
// log.Fatal("Fatal log example") // will call os.Exit(1) after logging
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment