Mongodb Hooks for Logrus ![:walrus: :walrus:](https://camo.githubusercontent.com/cad5cef19f4709026d903572dfb5fe5a75d090d95dd822ddef499e131e63337a/687474703a2f2f692e696d6775722e636f6d2f68546556776d4a2e706e67)
$ go get github.com/weekface/mgorus
package main
import (
"github.com/sirupsen/logrus"
"github.com/weekface/mgorus"
)
func main() {
log := logrus.New()
hooker, err := mgorus.NewHooker("localhost:27017", "db", "collection")
if err == nil {
log.Hooks.Add(hooker)
} else {
fmt.Print(err)
}
log.WithFields(logrus.Fields{
"name": "zhangsan",
"age": 28,
}).Error("Hello world!")
}
With authentication:
package main
import (
"github.com/sirupsen/logrus"
"github.com/weekface/mgorus"
)
func main() {
log := logrus.New()
hooker, err := mgorus.NewHookerWithAuth("localhost:27017", "db", "collection", "user", "pass")
if err == nil {
log.Hooks.Add(hooker)
} else {
fmt.Print(err)
}
log.WithFields(logrus.Fields{
"name": "zhangsan",
"age": 28,
}).Error("Hello world!")
}
MIT