ant_logger

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: MIT Imports: 7 Imported by: 0

README

ant-logger

Make logger interface for different implementations logger providers like uber-zap or loggrus, this permit easy extending for other logger implementations

Installations

go get github.com/aeolabs/ant-logger

Usage
package main

import(
    antlogger "github.com/aeolabs/ant-logger"
)

func main()  {
 logger := antlogger.NewLogger(antloger.InstanceZapLogger)
 logger.Infof("test")
}
Config usage
Thanks to

The code were based in https://www.mountedthoughts.com/golang-logger-interface

Documentation

Index

Constants

View Source
const (
	//Debug has verbose message
	Debug = "debug"
	//Info is default log level
	Info = "info"
	//Warn is for logging messages about possible issues
	Warn = "warn"
	//Error is for logging errors
	Error = "error"
	//Fatal is for logging fatal messages. The sytem shutsdown after logging the message.
	Fatal = "fatal"
)
View Source
const (
	ZapLogger int = iota
	LogrusLogger
)

Variables

This section is empty.

Functions

func Debugf

func Debugf(format string, args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func InitLogger

func InitLogger(loggerInstance int) error

func InitLoggerWithConfig

func InitLoggerWithConfig(config Configuration, loggerInstance int) error

func Panicf

func Panicf(format string, args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

Types

type Configuration

type Configuration struct {
	EnableConsole     bool
	Production        bool
	ConsoleJSONFormat bool
	ConsoleLevel      string
	EnableFile        bool
	FileJSONFormat    bool
	FileLevel         string
	FileLocation      string
}

Configuration stores the config for the logger For some loggers there can only be one level across writers, for such the level of Console is picked by default

type Fields

type Fields map[string]interface{}

Fields Type to pass when we want to call WithFields for structured logging

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})

	Infof(format string, args ...interface{})

	Warnf(format string, args ...interface{})

	Errorf(format string, args ...interface{})

	Fatalf(format string, args ...interface{})

	Panicf(format string, args ...interface{})

	WithFields(keyValues Fields) Logger
}

Logger is our contract for the logger

func NewLogrusLogger added in v1.0.1

func NewLogrusLogger(config Configuration) (Logger, error)

func NewZapLogger added in v1.0.1

func NewZapLogger(config Configuration) (Logger, error)

func WithFields

func WithFields(keyValues Fields) Logger

Jump to

Keyboard shortcuts

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