Skip to content

kennykarnama/logrus-bolt-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logrus-bolt-hook

Use this to log into Bolt. This hook is created because i need to practice about go programming language. So it is still in initial development version. It only logs into bolt, with key initiated by default using uuid and the value is the entry itself.

Usage

The hook could be configured using options provided:

type HookOptions struct {
	IDGenerator UniqueID
	Dbpath      string
	FileMode    os.FileMode
	BoltOptions *bolt.Options
}

Example:

boltHook := boltlogrus.NewBoltHook(boltlogrus.Dbpath("customlog.db"))
log.AddHook(boltHook)
	log.WithFields(log.Fields{
		"animal": "Dog",
		"number": "1",
	}).Info("Kenny")

To see the result of the logging, you could use bolter

Custom IDGenerator

If you want to implement your own IDGenerator, you just need to implement the interface specified in uniqueid.go Register your new IDGenerator by using IDGenerator(youOwn) inside the function of NewBoltHook. You could take a look in hook_test.go

Silent the log

Sometimes you may need to not display the log message to your default terminal console. This may happen when you use multiple hook. Same thing will be logged twice inside your terminal console. hmm, you don't like, do you. So to prevent this, you could try this :

silentLog := logrus.New()
var b bytes.Buffer
silentLog.SetOutput(&b)
//Same goes here, add your newhook

or just use, ioutil.Discard

Resources

This hook uses two dependencies of libary :

  1. logrus
  2. bolt
  3. uuid
  4. mockery for generating mock of uniqueid interface
  5. testify for assertion

You could read more at those sources

Contributions

Any contributions including Creating Issues & PR are appreciated.

About

Simple logrus hook for bolt

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages