yalogi

package module
v0.0.0-...-2b8db3a Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2019 License: MIT Imports: 4 Imported by: 23

README

Yalogi

Yalogi means "Yet Another Logger Interface" and provides a simple logger interface for use it in my golang projects.

Usage

It offers a log interface for unstructured and leveled log system. It can be used with some popular log libraries like logrus or zap.

func main() {
	//instantiate the logrus logger
	logger := logrus.New()
	logger.SetLevel(logrus.DebugLevel)

	//we can use logrus because satisfaces the interface yalogi
	withYalogi(logger)

	//we can convert to a standar log
	standarlog := yalogi.NewStandard(logger, yalogi.Info)
	standarlog.Printf("mensaje a un log estandar %v informativo\n", 1234)

	fmt.Println("fin de programa")
}

func withYalogi(logger yalogi.Logger) {
	logger.Debugf("esto es debug")
	logger.Infof("esto es informativo")
	logger.Warnf("esto es una advertencia")
}

Also it includes a null implementation yalogi.LogNull for no logging that can be used as a default log for a component.

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

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

Directories

Path Synopsis
examples
zap

Jump to

Keyboard shortcuts

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