Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecCloser ¶
ExecCloser write the logrus entry to the database and close the database
func NewExec ¶
func NewExec(sess *mgo.Session, dbName, cName string) ExecCloser
NewExec create an exec instance
func NewExecWithURL ¶
func NewExecWithURL(url, dbName, cName string) ExecCloser
NewExecWithURL create an exec instance
type FilterHandle ¶
FilterHandle a filter handler
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook to send logs to a mongo database
Example ¶
sess, err := mgo.Dial(mgoURL) if err != nil { fmt.Println(err) return } defer sess.Close() cName := "e_log" hook := mongohook.Default(sess, dbName, cName) defer sess.DB(dbName).C(cName).DropCollection() log := logrus.New() log.AddHook(hook) log.WithField("foo", "bar").Info("foo test") hook.Flush() var item struct { Message string `bson:"message"` } err = sess.DB(dbName).C(cName).Find(nil).Select(bson.M{"_id": 0, "message": 1}).One(&item) if err != nil { fmt.Println(err) return } fmt.Println(item.Message)
Output: foo test
func DefaultWithURL ¶
DefaultWithURL create a default mongo hook
Click to show internal directories.
Click to hide internal directories.