Help us shape the future of Go! Take the 2026 Go Developer Survey

logrus_env

package module
v0.0.0-...-367f558 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: BSD-2-Clause Imports: 3 Imported by: 1

README

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")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogrusEnvHook

type LogrusEnvHook struct {
	Values map[string]string
}

func NewHook

func NewHook(keys []string) LogrusEnvHook

func (LogrusEnvHook) Fire

func (hook LogrusEnvHook) Fire(entry *logrus.Entry) error

Fire is called by logrus when something is logged.

func (LogrusEnvHook) Levels

func (hook LogrusEnvHook) Levels() []logrus.Level

Levels provides the levels to run the hook on.

Jump to

Keyboard shortcuts

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