Skip to content

Commit 80d83a7

Browse files
committed
Added logging info to readme
1 parent 6ece76d commit 80d83a7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,42 @@ Here you can check a small tutorial of how to use this component in an orders sc
3535

3636
[Tutorial](docs/how_to.md)
3737

38+
## Logging
39+
40+
GoEngine uses default `log` package for debug logging. If you want to use your own logger - `goengine.SetLogHandler()`
41+
is available. Here is how you can use, e.g. `github.com/sirupsen/logrus` for logging:
42+
43+
```go
44+
package main
45+
46+
import (
47+
"github.com/hellofresh/goengine"
48+
log "github.com/sirupsen/logrus"
49+
)
50+
51+
func main() {
52+
goengine.SetLogHandler(func(msg string, fields map[string]interface{}, err error) {
53+
if nil == fields && nil == err {
54+
log.Debug(msg)
55+
} else {
56+
var entry *log.Entry
57+
if fields != nil {
58+
entry = log.WithFields(log.Fields(fields))
59+
if nil != err {
60+
entry = entry.WithError(err)
61+
}
62+
} else {
63+
entry = log.WithError(err)
64+
}
65+
66+
entry.Debug(msg)
67+
}
68+
})
69+
70+
// do your application stuff
71+
}
72+
```
73+
3874
## Contributing
3975

4076
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

0 commit comments

Comments
 (0)