loggers

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2018 License: MIT Imports: 3 Imported by: 0

README

loggers

The loggers package provides you with a way to utilize either a pre-built logger shim for popular loggers or write a custom logger shim that implements the ILogger interface (and thus is usable by the health lib).

This has to be done since the loggers package in the standard library does not provide a logger interface.

Options

By default, health will utilize the standard library loggers package.

If you do not wish for health to perform any sort of logging, you can update h.Logger to point to a noop logger: h.Logger = loggers.NewNoop().

Example w/ logrus

import (
    "github.com/InVisionApp/go-health"
    "github.com/InVisionApp/go-health/loggers"
    "github.com/InVisionApp/go-health/checkers"
)

// create and configure a health instance
h := health.New()
h.AddChecks(...)

// Set the logger
h.Logger = loggers.NewLogrus(nil)

// Or alternatively, you can provide your own logrus instance
myLogrus := logrus.WithField("foo", "bar")
h.Logger = loggers.NewLogrus(myLogrus)

// Start healthcheck
h.Start()

Example w/ Noop logger

import (
    "github.com/InVisionApp/go-health"
    "github.com/InVisionApp/go-health/loggers"
    "github.com/InVisionApp/go-health/checkers"
)

// create and configure a health instance
h := health.New()
h.AddChecks(...)

h.Logger = loggers.NewNoop()

// Start healthcheck
h.Start()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBasic

func NewBasic() *basic

NewBasic creates a simple logger that is used internally by the health pkg when the user has not supplied their own logger.

func NewNoop

func NewNoop() *noop

NewNoop creates a noop logger that can be used to silence all logging from this library.

Types

type ILogger

type ILogger interface {
	Debug(msg string, args map[string]interface{})
	Info(msg string, args map[string]interface{})
	Warn(msg string, args map[string]interface{})
	Error(msg string, args map[string]interface{})
}

ILogger interface allows you to use a custom logger. Since the `loggers` pkg does not expose an interface for a logger (and there is no "accepted" interface), we roll our own and supplement it with some helpers/shims for common logging libraries such as `logrus`. See [DOC.md(DOCS.md#Logging).

func NewLogrus

func NewLogrus(logger *logrus.Entry) ILogger

NewLogrus can be used to override the default logger in the `health` pkg. Optionally pass in an existing logrus logger or pass in `nil` to have a field logger created on the fly.

Jump to

Keyboard shortcuts

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