Skip to content

marzagao/logrus-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

logrus-env: Environment variables hook for Logrus

Pass-thru hook that sets the values of a given set of environment variables into logrus entries.

Usage

Initialize the hook by passing the keys of all environment variables you wish to include in your logrus entries. Example:

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/marzagao/logrus-env"
)

func main() {
	logger := logrus.New()
	hook := logrus_env.NewHook([]string{"VARIABLE", "ANOTHER_VARIABLE"})
	logger.Hooks.Add(hook)
}

Result

The result is that if you have a logging statement like this:

	logger.WithFields(logrus.Fields{
		"someKey": "someValue",
	}).Info("something happened here")

And you initialize the hook like in the example from the Usage section, the end result will be the same as if you had done:

	logger.WithFields(logrus.Fields{
		"someKey":         "some value",
		"variable":        "value of env variable",
		"anotherVariable": "value of another env variable",
	}).Info("something happened here")

About

Environment variables hook for Logrus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages