mgorus

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 4 Imported by: 10 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hooker

type Hooker struct {
	// contains filtered or unexported fields
}

Hooker is a logrus hooker for mongodb

func NewHooker

func NewHooker(mgoURL, db, collection string) (*Hooker, error)

NewHooker dials a mongodb server without authentication or encryption and readies the hook to place logs inside of the given collection

func NewHookerFromSession

func NewHookerFromSession(session *mgo.Session, db, collection string) *Hooker

NewHookerFromSession makes a copy of an existing mongodb session and readies the hook to place logs inside of the given collection

func (*Hooker) Fire

func (h *Hooker) Fire(entry *logrus.Entry) error

Fire places a logrus entry into the log collection

func (*Hooker) Levels

func (h *Hooker) Levels() []logrus.Level

Levels returns the logrus levels the hook supports

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL