logger

package module
v0.0.0-...-3a8b1d2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 5 Imported by: 0

README

logger

Simple Logger

This simple Logger is a wrapper on zap SugaredLogger, provides different levels of logging, debug, info, error, fatal etc.

To Create a logger, you must provide logger config as follow

config := logger.Configuration{
       EnableConsole:     true,
       ConsoleLevel:      logger.InfoLevel,
       ConsoleJSONFormat: false,
       EnableFile:        true,
       FileLevel:         logger.DebugLevel,
       FileJSONFormat:    false,
       FileLocation:      "log.log",
   }

Instantiate logger

   log, err := logger.NewLogger(config)
   if err != nil {
       log.Fatalf("Could not instantiate log %s", err.Error())
   }

Using logger

   logger.Info("This is info")
   logger.Error("This is error")
   logger.Debug("This is debug")
   logger.Fatal("fatal Error")

Documentation

Index

Constants

View Source
const (
	DebugLevel            = "debug"
	InfoLevel             = "info"
	WarnLevel             = "warn"
	ErrorLevel            = "error"
	FatalLevel            = "fatal"
	InstanceZapLogger int = iota
)

Variables

This section is empty.

Functions

func Debug

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

func Error

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

func Fatal

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

func Info

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

func Panic

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

func Warn

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

Types

type Configuration

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

Configuration stores the config for the logger

type Fields

type Fields map[string]interface{}

type Logger

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

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

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

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

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

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

	WithContext(keyValues Fields) Logger
}

Logger is our contract for the logger

func NewLogger

func NewLogger(config Configuration) (Logger, error)

func NewZapLogger

func NewZapLogger(config Configuration) (Logger, error)

func WithContext

func WithContext(keyValues Fields) Logger

Jump to

Keyboard shortcuts

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