Last active
June 30, 2022 10:59
-
-
Save iyashjayesh/6081706eb212cdb9dcf3922c49d3e57d to your computer and use it in GitHub Desktop.
Golang Logrus Simple Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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