Documentation ¶
Overview ¶
Package yalogi means "Yet Another Logger Interface" and provides a simple logger interface for use it in my projects.
Feel free to use it in yours ;)
This package is a work in progress and makes no API stability promises.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var LogNull = &nullLogger{}
LogNull is an instance of a logger object that does nothing
Functions ¶
Types ¶
type Logger ¶
type Logger interface { Debugf(template string, args ...interface{}) Infof(template string, args ...interface{}) Warnf(template string, args ...interface{}) Errorf(template string, args ...interface{}) Fatalf(template string, args ...interface{}) }
Logger is the main interface of the package
Example ¶
package main import ( "os" "github.com/luisguillenc/yalogi" "github.com/sirupsen/logrus" ) func main() { withYalogi := func(logger yalogi.Logger) { logger.Debugf("esto es debug") logger.Infof("esto es informativo") logger.Warnf("esto es una advertencia") } //instantiate the logrus logger logger := logrus.New() formatter := &logrus.TextFormatter{ DisableColors: true, DisableTimestamp: true, } logger.SetFormatter(formatter) logger.SetLevel(logrus.DebugLevel) logger.SetOutput(os.Stdout) //we can use logrus in func because satisfaces the interface yalogi withYalogi(logger) //we can convert a yalogi to a standar log standarlog := yalogi.NewStandard(logger, yalogi.Info) standarlog.Printf("mensaje a un log estandar %v informativo\n", 1234) }
Output: level=debug msg="esto es debug" level=info msg="esto es informativo" level=warning msg="esto es una advertencia" level=info msg="mensaje a un log estandar 1234 informativo\n"
Click to show internal directories.
Click to hide internal directories.