Categorygithub.com/ocmdev/mgorus
modulepackage
0.1.1
Repository: https://github.com/ocmdev/mgorus.git
Documentation: pkg.go.dev

# README

Mongodb Hooks for Logrus :walrus:

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.

# Structs

Hooker is a logrus hooker for mongodb.