import ( "github.com/sirupsen/logrus" "os" ) func main() { log := logrus.New() log.Out = os.Stdout fields := logrus.Fields{ "animal": "walrus", "number": 1, "size": 10, } log.WithFields(fields).Info("A walrus appears") }
func myFunction() { log := logrus.WithFields(logrus.Fields{ "task": "myFunction", "user": "john", }) // do some work ... log.Debug("Function finished.") }In this example, we use the `WithFields()` method to create a Logger instance with specific fields assigned to the logger. We then execute some function and use `Debug()` to log a message once the function has completed. Overall, sirupsen/logrus is a very powerful and flexible logging library for Go that provides a wide range of features and capabilities to developers.