yalogi

package
v0.0.0-...-a54a33a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2020 License: AGPL-3.0 Imports: 4 Imported by: 49

Documentation

Overview

Package yalogi means "Yet Another Logger Interface" and provides a simple logger interface.

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

func NewStandard

func NewStandard(l Logger, lvl Level) *log.Logger

NewStandard creates a new instance of a golang standard log from an object that satisfaces the Logger interface. It is to provide compatibility in applications with packages that use the standard interface.

Types

type Level

type Level int

Level type can be used to classify the level of log messages.

const (
	Debug Level = iota
	Info
	Warning
	Error
	Fatal
)

Constants for levels.

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/sirupsen/logrus"

	"github.com/luids-io/core/yalogi"
)

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"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL