# README
Mongodb Hooks for Logrus 
Install
$ go get github.com/weekface/mgorus
Usage
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!")
}
License
MIT
# Functions
NewHooker dials a mongodb server without authentication or encryptionand readies the hook to place logs inside of the given collection.
NewHookerFromSession makes a copy of an existing mongodb sessionand readies the hook to place logs inside of the given collection.