import ( "github.com/sirupsen/logrus" ) func main() { log := logrus.New() log.WithFields(logrus.Fields{ "animal": "walrus", "size": 10, }).Info("A group of walrus emerges from the ocean") }
import ( "github.com/sirupsen/logrus" ) var log *logrus.Entry func init() { log = logrus.WithFields(logrus.Fields{ "app": "myapp", "module": "mymodule", }) } func myFunc() { log.Infof("Hello from myFunc") }In this code snippet, we create a custom logger for our application by pre-configuring fields to be included in all log entries using the WithFields method. Then, we create a global variable log of type Entry and set it to the pre-configured logger instance. Finally, we use log variable to log a message from myFunc with added Info severity level. Thus, the package library in use is "github.com/sirupsen/logrus".