Documentation ¶
Overview ¶
Package logrus provides a logger implementation based on the github.com/sirupsen/logrus pkg
Index ¶
- Constants
- Variables
- func ConfigGetter(e config.ExtraConfig) interface{}
- type Config
- type Entry
- func (e *Entry) Critical(v ...interface{})
- func (e *Entry) Debug(v ...interface{})
- func (e *Entry) Error(v ...interface{})
- func (e *Entry) Fatal(v ...interface{})
- func (e *Entry) Info(v ...interface{})
- func (e *Entry) Warning(v ...interface{})
- func (entry *Entry) WithField(key string, value interface{}) *Entry
- type Logger
- func (l *Logger) Critical(v ...interface{})
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) NewEntry() *Entry
- func (l *Logger) Warning(v ...interface{})
- func (l *Logger) WithField(key string, value interface{}) *Entry
Examples ¶
Constants ¶
const Namespace = "github_com/devopsfaith/krakend-logrus"
Namespace is the key to look for extra configuration details
Variables ¶
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 Entry ¶ added in v0.0.3
An entry is the final or intermediate Logrus logging entry. It contains all the fields passed with WithField{,s}. It's finally logged when Trace, Debug, Info, Warn, Error, Fatal or Panic is called on it. These objects can be reused and passed around as much as you wish to avoid field duplication.
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