simplelog

package module
v0.0.0-...-846caab Latest Latest
Warning

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

Go to latest
Published: May 7, 2017 License: MIT Imports: 4 Imported by: 4

README

simplelog

Simple logging library

Documentation

Overview

Package simplelog provides a dead simple logging system.

Index

Constants

View Source
const (
	LevelDebug   int = iota // Threshold for Debug log level
	LevelInfo               // Threshold for Info log level
	LevelWarning            // Threshold for Warning log level
	LevelError              // Threshold for Error log level
	LevelFatal              // Threshold for Fatal log level (will crash the program when used)
)

Constants for the different log levels supported by the library

Variables

View Source
var (
	Fatal   = &LogLevel{prefix: "FATAL: ", level: LevelFatal, destination: os.Stderr}
	Error   = &LogLevel{prefix: "ERROR: ", level: LevelError, destination: os.Stderr}
	Warning = &LogLevel{prefix: "WARNING: ", level: LevelWarning, destination: os.Stderr}
	Info    = &LogLevel{prefix: "INFO: ", level: LevelInfo, destination: os.Stdout}
	Debug   = &LogLevel{prefix: "DEBUG: ", level: LevelDebug, destination: os.Stdout}
)

Logger objects that will be used to perform the actual logging. Each of them represents a different logging level and can be pointed to a different backend (file, stdout, etc...) TODO: Allow for a method to change log destination of a logging level (and potentially of all log levels)

View Source
var (
	ErrInvalidThreshold = errors.New("Invalid Threshold. Need one between LevelDebug and LevelFatal") // When an invalid threshold has been defined
)

Common errors that can be returned

Functions

func IsDebug

func IsDebug() bool

IsDebug will return true if logging threshold is currently set at Debug level

func LogThreshold

func LogThreshold() int

LogThreshold will return the current log level

func SetThreshold

func SetThreshold(t int) error

SetThreshold sets the logging threshold level. Will return InvalidThreshold if new threshold isn't in the accepted range

Types

type LogLevel

type LogLevel struct {
	// contains filtered or unexported fields
}

LogLevel represents a logger object for a given log level.

func (*LogLevel) Printf

func (l *LogLevel) Printf(format string, v ...interface{})

Printf will use the logger attached to this LogLevel to write a log message. Message will only get written if current log level allows it (it won't write INFO messages if we're at ERROR) When writing to the Fatal log level the program will automatically exit with status code 1 TODO: Prepend the name of the application doing the logging to the msg (if it has been defined)

func (*LogLevel) Println

func (l *LogLevel) Println(v ...interface{})

Println will use the logger attached to this LogLevel to write a log message. Message will only get written if current log level allows it (it won't write INFO messages if we're at ERROR) When writing to the Fatal log level the program will automatically exit with status code 1 TODO: Prepend the name of the application doing the logging to the msg (if it has been defined)

Jump to

Keyboard shortcuts

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