logger

package module
v0.0.0-...-5ef54d6 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: GPL-2.0 Imports: 6 Imported by: 0

README

go-logger

Logging package

Documentation

Index

Constants

View Source
const ChanBuffSize = 10

ChanBuffSize defines the size of channel buffers

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Message   string         `json:"message"`
	Component string         `json:"component"`
	Time      time.Time      `json:"time"`
	Level     VerbosityLevel `json:"level"`
}

Event contains log message and metadata

func NewEvent

func NewEvent(msg string, component string, logLevel VerbosityLevel) Event

NewEvent creates an event

func (Event) EventString

func (e Event) EventString() (string, VerbosityLevel)

EventString return a formatted string and the VerbosityLevel

func (Event) Write

func (e Event) Write(l *Logger)

Write commits the event to the logger

type LevelType

type LevelType struct {
	Name  string
	Level VerbosityLevel
}

LevelType defines level types

func GetDefaultLevelTypes

func GetDefaultLevelTypes() []LevelType

GetDefaultLevelTypes returns default level type schema

func RetrieveLevel

func RetrieveLevel(levelType []LevelType, level VerbosityLevel) LevelType

RetrieveLevel return the LevelType that matches VerbosityLevel

type Logger

type Logger struct {
	In chan Event

	// RotationLen defines how many log entries to keep in memory/log to file
	RotationLen int
	// RetainLogs should be set to true to save logs to a file
	RetainLogs bool

	LogPrefix   string
	LogFileDir  string
	LogFilePerm os.FileMode
	// contains filtered or unexported fields
}

Logger should be initialized if created manually and Handle() method should be called to start logging

func NewLogger

func NewLogger() *Logger

NewLogger creates and initialites a logger

func (*Logger) Init

func (l *Logger) Init()

Init intializes the logger (makes channels, maps)

func (*Logger) NewEvent

func (l *Logger) NewEvent(e Event)

NewEvent pushes a new event into the channel In

func (*Logger) SetLevels

func (l *Logger) SetLevels(levelType []LevelType)

SetLevels sets internal levels to new - user provided levels

func (*Logger) WriteLogFile

func (l *Logger) WriteLogFile() error

WriteLogFile writes the log to a file on the disk

type VerbosityLevel

type VerbosityLevel int

VerbosityLevel contains the log verbosity level (WARNING, ERROR, FATAL, ...)

Jump to

Keyboard shortcuts

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