modulepackage
1.0.2
Repository: https://github.com/speijnik/logrus-modular.git
Documentation: pkg.go.dev
# README
speijnik/logrus-modular
Package speijnik/logrus-modular
implements modular logging for logrus.
This allows creation of a hierarchy of loggers, whereas log-levels may be inherited. The purpose of this library is simplifying the handling of loggers which can be logically grouped and allowing configuration of log-levels on such logger groups.
Install
With a correctly configured Go toolchain:
go get -u gopkg.in/speijnik/logrus-modular.v1
Examples
package main
import (
"os"
"github.com/sirupsen/logrus"
"gopkg.in/speijnik/logrus-modular.v1"
)
func main() {
log := logrus.New()
log.Level = logrus.DebugLevel
log.Out = os.Stdout
rootLogger := modular.NewRootLogger(log)
testModule := rootLogger.GetOrCreateChild("test", logrus.InfoLevel)
testTestModule := rootLogger.GetOrCreateChild("test.test", logrus.DebugLevel)
// No-op, log level for "test" module is Info
testModule.Debug("No-op, log-level is info")
testModule.Info("Info message")
testTestModule.Debug("Debug message of child module")
// Logs "test2", log level for "test.test" module is Debug
// Set level of "test" module to Info, which will propagate to child
// module "test.test"
testModule.SetLevel(logrus.InfoLevel)
// No-op, log level for "test.test" module is Info
testTestModule.Debug("No-op, SetLevel propagated Info level to child")
testTestModule.Info("Another info message")
}
# Packages
No description provided by the author
# Functions
NewRootLogger creates a new root logger, that wraps the passed logrus.Logger.
# Constants
DefaultModuleField defines the default field to use for the module name.
# Variables
ErrChildExists denotes that a child logger already exists.
ErrChildNotFound denotes that a child logger was not found.
# Interfaces
Logger defines the baseline logger interface.
ModuleLogger defines the interface implemented by a module logger.
RootLogger defines the interface implemented by a root logger.