logger

package module
v0.0.0-...-616d07d Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: MIT Imports: 10 Imported by: 0

README

go-logger

Logger interface so that your application code does not depend on the implementation. Make sure to turn the go moudles on if you are inside the $GOPATH. Type the below in your terminal and press enter:

export GO111MODULE=on;

and for use:

go get github.com/navono/go-logger

base code initially from amitrai48.

Documentation

Index

Constants

View Source
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel = "debug"

	// InfoLevel is the default logging priority.
	InfoLevel = "info"

	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel = "warn"

	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = "error"

	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = "fatal"
)
View Source
const (
	// InstanceZapLogger will be used to create Zap instance for the logger
	InstanceZapLogger int = iota
	// InstanceLogrusLogger will be used to create Logrus instance for the logger
	InstanceLogrusLogger
)

Variables

This section is empty.

Functions

func GetConcreteLogger

func GetConcreteLogger(log Logger) interface{}

GetConcreteLogger returns the underlying log instance

func NewContextHook

func NewContextHook(skip int, levels ...logrus.Level) logrus.Hook

NewContextHook use to make an hook

Types

type Configuration

type Configuration struct {
	EnableConsole     bool
	ConsoleJSONFormat bool
	ConsoleLevel      string

	// EnableFile that whether to log information to a file
	EnableFile bool

	// FileLevel is the log need json format for file
	FileJSONFormat bool

	// FileLevel is the log level that for file
	FileLevel string

	// Filename is the file to write logs to.  Backup log files will be retained
	// in the same directory.
	Filename string

	// FileMaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	FileMaxSize int

	// FileMaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	FileMaxAge int

	// Skip count for caller stack. Zap and logrus have different skip count
	Skip int
	// contains filtered or unexported fields
}

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

func (*Configuration) SetLevel

func (c *Configuration) SetLevel(l string) error

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 NewLogger

func NewLogger(config *Configuration, loggerInstance int) (Logger, error)

NewLogger returns an instance of Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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