modulepackage
2.1.0+incompatible
Repository: https://github.com/nivl/go-logger.git
Documentation: pkg.go.dev
# README
go-logger
go-logger contains interfaces and basic implementations to deal with loggers
Usage
m := logger.NewManagerWithTag("[my-app]")
// Add a bunch of loggers
m.Add(logger.NewStderrLogger())
m.Add(NewFileLogger())
// send a log to all the loggers added with Add()
m.Errorf("error message: %s", "file not found") // prints "[ERROR][my-app] error message: file not found"
// create sub-loggers for specific parts of your app
// Sub-loggers can have their own loggers, but also reuse their parent's loggers
sm := m.NewSubLogger("[parser]")
sm.Log("foo") // prints "[my-app][parser] foo"
Provided implementations
gomock
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
m := mocklogger.NewMockManager(mockCtrl)
m.EXPECTS().Log("foo")
StderrLogger (log.Print() wrapper)
m := logger.NewManager()
m.Add(logger.NewStderrLogger())
m.Error("foobar") // printed on stderr
# Packages
Package mocklogger is a generated GoMock package.
# Functions
Add adds a logger returns ErrAlreadyExist if the logger has already been added.
AddGlobalData is used to add data that will be added to all logs.
Close safely removes all the loggers All submanagers will also be closed returns a list of errors if a logger could not be safely removed.
Debug logs a message that is intended for use in a development environment while actively debugging your subsystem, not in shipping software Arguments are handled in the manner of fmt.Println.
Debugf logs a message that is intended for use in a development environment while actively debugging your subsystem, not in shipping software Arguments are handled in the manner of fmt.Printf.
Error logs an error message Arguments are handled in the manner of fmt.Println.
Errorf logs an error message Arguments are handled in the manner of fmt.Printf.
FullTag returns the full tag (including parents) of the manager.
ID returns the manager's unique ID.
Info logs a message that may be helpful, but isn’t essential, for troubleshooting Arguments are handled in the manner of fmt.Println.
Infof logs a message that may be helpful, but isn’t essential, for troubleshooting Arguments are handled in the manner of fmt.Printf.
Log logs a message that might result a failure Arguments are handled in the manner of fmt.Println.
Logf logs a message that might result a failure Arguments are handled in the manner of fmt.Printf.
NewManager creates a new manager.
NewManagerWithTag create a new manager tagged with the given tag.
NewStderrLogger creates and returns a logger that writes on stderr.
NewSubManager creates a new manager that can have its own loggers.
Remove safely removes a logger returns an Error struct if a logger could not be safely removed.
RemoveGlobalData is used to remove data that are added to all logs.
SetTag adds a tag to the logs.
Tag returns the tag of the manager.
# Variables
List of all errors.
# Structs
DefaultManager is a basic go-routine safe logger.
Err represents an error caused by a specific logger.
StderrLogger is a non-buffered logger that writes on stderr.