Skip to content

wking/go-log

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log GoDoc

Log is a logging interface for Go. That's it. Pass around the interface.

Rationale

Users want to standardise logging. Sometimes libraries log. We leave the underlying logging implementation to the user while allowing libraries to log by simply expecting something that satisfies the Logger interface. This leaves the user free to pre-configure structure, output, etc.

Interface

The interface is minimalistic on purpose

type Logger interface {
    Log(v ...interface{})
    Logf(format string, v ...interface{})
}

Example

Pre-configure a logger using WithFields and pass it as an option to a library:

import (
	"github.com/go-log/log/print"
	"github.com/lib/foo"
	"github.com/sirupsen/logrus"
)

logger := print.New(logrus.WithFields(logrus.Fields{
	"library": "github.com/lib/foo",
}))

f := foo.New(logger)

About

A universal log interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%