logwrap

package module
v0.0.0-...-a178c58 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2018 License: MIT Imports: 2 Imported by: 5

README

logrwap

GoDoc Go Report Card

A thin layer around Go's standard library logger. It was extracted from github.com/digineo/fastd/fastd.

Consumers of this package should simply instantiate a log instance, like so:

import "github.com/digineo/go-logwrap"

var (
	log       = &logwrap.Instance{}
	SetLogger = log.SetLogger
)

This then allows your consumers to plug in their own favorite logger:

import (
	"github.com/digineo/fastd/fastd"
	"github.com/sirupsen/logrus"
)

func init() {
	fastd.SetLogger(logrus.WithField("component", "pkg"))
}

You are not limited to sirupsen/logrus -- your logger only needs to implement this interface:

type Logger interface {
	Infof(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

where both methods implement fmt.Printf semantics.

This should be compatible with:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

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

Instance allows to instantiate multiple loggers. It is recommended to use only one logger instance per package.

func (*Instance) Errorf

func (i *Instance) Errorf(format string, a ...interface{})

Errorf logs a message with ERROR log level. format and args implement fmt.Printf semantics.

func (*Instance) Infof

func (i *Instance) Infof(format string, a ...interface{})

Infof logs a message with INFO log level. format and args implement fmt.Printf semantics.

func (*Instance) SetLogger

func (i *Instance) SetLogger(l Logger)

SetLogger updates the logger fastd uses. If l is nil, we'll simply wrap the standard log package.

type Logger

type Logger interface {
	Infof(format string, a ...interface{})
	Errorf(format string, a ...interface{})
}

Logger defines log methods used by this package.

Jump to

Keyboard shortcuts

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