package main import ( "github.com/sirupsen/logrus" ) func main() { // Create a new Logrus logger log := logrus.New() // Create a new log entry with a "user" field entry := log.WithField("user", "alice") // Log a message using the new log entry entry.Info("User logged in") }
package main import ( "github.com/sirupsen/logrus" ) func main() { // Create a new Logrus logger log := logrus.New() // Create a new log entry with both "user" and "status" fields entry := log.WithFields(logrus.Fields{ "user": "bob", "status": "success", }) // Log a message using the new log entry entry.Info("API request completed") }In this example, we create a new log entry with two fields: "user" set to "bob" and "status" set to "success". We then use this entry to log an "info" message indicating that an API request has completed. Overall, the "github.com/sirupsen/logrus" package is a useful tool for logging in Go projects. The "Entry" type and "WithField" method provide a structured and flexible way to add context and metadata to log messages.