Documentation ¶
Overview ¶
Package logrus provides a logger implementation based on the github.com/sirupsen/logrus pkg
Index ¶
Examples ¶
Constants ¶
View Source
const Namespace = "github_com/devopsfaith/krakend-logrus"
Namespace is the key to look for extra configuration details
Variables ¶
View Source
var ErrWrongConfig = errors.New("getting the extra config for the krakend-logrus module")
ErrWrongConfig is the error returned when there is no config under the namespace
Functions ¶
func ConfigGetter ¶
func ConfigGetter(e config.ExtraConfig) interface{}
ConfigGetter implements the config.ConfigGetter interface
Example ¶
cfg := ConfigGetter(newExtraConfig("DEBUG")).(Config) fmt.Println(cfg.JSONFormatter) fmt.Printf("%+v\n", cfg.TextFormatter)
Output: <nil> &{ForceColors:false DisableColors:false DisableTimestamp:false FullTimestamp:true TimestampFormat: DisableSorting:false DisableLevelTruncation:false QuoteEmptyFields:false isTerminal:false FieldMap:map[] Once:{m:{state:0 sema:0} done:0}}
Types ¶
type Config ¶
type Config struct { Level string `json:"level"` StdOut bool `json:"stdout"` Syslog bool `json:"syslog"` Module string `json:"module"` TextFormatter *logrus.TextFormatter `json:"text"` JSONFormatter *logrus.JSONFormatter `json:"json"` }
Config is the custom config struct containing the params for the logger
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a wrapper over a github.com/sirupsen/logrus logger
func NewLogger ¶
NewLogger returns a krakend logger wrapping a logrus logger
Example ¶
cfg := map[string]interface{}{ Namespace: Config{ Level: "DEBUG", Module: "pref", Syslog: false, StdOut: false, TextFormatter: &logrus.TextFormatter{ DisableTimestamp: true, }, }, } buff := new(bytes.Buffer) logger, err := NewLogger(cfg, buff) if err != nil { fmt.Println(err.Error()) } logger.Debug(debugMsg) logger.Info(infoMsg) logger.Warning(warningMsg) logger.Error(errorMsg) logger.Critical(criticalMsg) fmt.Println(buff.String())
Output: level=debug msg="Debug msg" module=pref level=info msg="Info msg" module=pref level=warning msg="Warning msg" module=pref level=error msg="Error msg" module=pref level=error msg="Critical msg" module=pref
func WrapLogger ¶
WrapLogger wraps already configured logrus instance
Example ¶
buff := new(bytes.Buffer) logrusLogger := logrus.New() logrusLogger.Formatter = &logrus.TextFormatter{DisableTimestamp: true} logrusLogger.SetLevel(logrus.DebugLevel) logrusLogger.SetOutput(buff) logger := WrapLogger(logrusLogger, "pref") logger.Debug(debugMsg) logger.Info(infoMsg) logger.Warning(warningMsg) logger.Error(errorMsg) logger.Critical(criticalMsg) fmt.Println(buff.String())
Output: level=debug msg="Debug msg" module=pref level=info msg="Info msg" module=pref level=warning msg="Warning msg" module=pref level=error msg="Error msg" module=pref level=error msg="Critical msg" module=pref
func (*Logger) Critical ¶
func (l *Logger) Critical(v ...interface{})
Critical implements the logger interface but demotes to the error level
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug implements the logger interface
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error implements the logger interface
Click to show internal directories.
Click to hide internal directories.