glog

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: MPL-2.0 Imports: 9 Imported by: 5

README

gLog

Your silver bullet logging solution. Because that is definitely what the world needed: another logging library.

Features

gLog supports the following features:

  • log-levels
  • smart-colors
  • customization
  • caller-insertion
  • mutiple outputs
  • log rotation (coming soon™)
  • panic-handling
  • conditionals:
    • output per logging level
    • caller from a certain level
  • sane defaults

Output

The output follows this structure:

%level:\t%time – %caller – …

%level is colored by default when logging to stdout or stderr. It can be enabled and disabled at will.

%time is in the ISO- format

%caller is the name (format: package.function) of the function that is logging the message. By default this does not happen for INFO and WARNING.

Levels

Level Description
TRACE Print everything. This is usually not wanted unless debugging.
DEBUG Print every function call.
INFO Print general statusmessages like HTTP-Requests (a good default)
WARNING Handled errors. (the better default¹)
ERROR Non-Critical Errors like access denied
FATAL Errors that do not allow the Program to continue

¹) "no news is good news" or so they say

License

© Moritz Poldrack

gLog is a gun unter the MPL-2.0

To learn more you may:

  • read the license-text here
  • take a look at the official FAQs
  • take a look at a summary at TLDRLegal

Documentation

Overview

glog aims to be the "one for all" logging package. It has a wide variety of features. To "handle errors gracefully" most times when a Setting-Function is called, no error is returned. If the specified level does not exist, execution is just silently aborted.

An important note is that *all* log-level ranges are inclusive. This means that "below …" actually means "below or equal to …".

Index

Constants

This section is empty.

Variables

View Source
var (

	// OverwriteColor allows overwriting the coloring mode. 0 = auto;
	// 1 = always; -1 = never
	//
	// This can also be set using the Environment-variable `GLOG_COLOR`
	OverwriteColor int8
	// LogLevel indicates the level of verbosity to use when logging.
	// Messages below the specified level are discarded.
	//
	// This can also be set using the Environment-variable `GLOG_LEVEL`
	LogLevel = WARNING
)
View Source
var (
	// TimeFormat specifies the formatting of the timestamp to use. The
	// default is ISO-8601 which corresponds to:
	TimeFormat = "2006-01-02T15:04:05-0700"
)

Functions

func AddLogFile

func AddLogFile(filepath string, lvls ...Level) (*os.File, error)

func AddOutput

func AddOutput(lvl Level, output io.Writer)

AddOutput adds the specified output to the list of outputs for the level

func AddOutputAbove

func AddOutputAbove(lvl Level, output io.Writer)

AddOutput adds the specified output to the list of outputs for the specified levels.

func AddOutputBelow

func AddOutputBelow(lvl Level, output io.Writer)

AddOutput adds the specified output to the list of outputs for the specified levels.

func AddOutputBetween

func AddOutputBetween(lowerLevel, upperLevel Level, output io.Writer)

AddOutputBetween adds the specified output to the list of outputs for all specified levels.

func Debug

func Debug(message ...interface{})

Debug logs a message at the DEBUG level

func Debugf

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

Debugf formats the input values as specified and writes them to the according channels

func Error

func Error(message ...interface{})

Error logs a message at the ERROR level

func Errorf

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

Errorf formats the input values as specified and writes them to the according channels

func Fatal

func Fatal(message ...interface{})

Fatal logs a message at the FATAL level and Panics afterwards

func Fatalf

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

Fatalf formats the input values as specified and writes them to the according channels

func Info

func Info(message ...interface{})

Info logs a message at the INFO level

func Infof

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

Infof formats the input values as specified and writes them to the according channels

func PlainStyle

func PlainStyle(content ...interface{}) string

PlainStyle is an implementation of StyleFunction that does not format output.

func SetOutput

func SetOutput(lvl Level, output io.Writer)

SetOutput removes all outputs and replaces them with the specified output. To discard log messages to this level set the loglevel accordingly or use `io.Discard`

func SetOutputAbove

func SetOutputAbove(lvl Level, output io.Writer)

SetOutputAbove removes all outputs and replaces them with the specified output. This is repeated for every specified level.

func SetOutputBelow

func SetOutputBelow(lvl Level, output io.Writer)

SetOutput removes all outputs and replaces them with the specified output. This is repeated for every specified level.

func SetOutputBetween

func SetOutputBetween(lowerLevel, upperLevel Level, output io.Writer)

SetOutputBetween removes all outputs and replaces them with the specified output. This is executed for all specified levels.

func SetShowCaller

func SetShowCaller(lvl Level, show bool)

func SetStyle

func SetStyle(lvl Level, styler StyleFunction)

SetStyle allows customizing the look of the *error-level*. This can also be used for changing the names of the loglevels.

func Trace

func Trace(message ...interface{})

Trace logs a message at the TRACE level

func Tracef

func Tracef(format string, values ...interface{})

Tracef formats the input values as specified and writes them to the according channels

func Warn

func Warn(message ...interface{})

Warn logs a message at the WARNING level

func Warnf

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

Warnf formats the input values as specified and writes them to the according channels

Types

type Level

type Level uint8
const (
	TRACE Level = iota
	DEBUG
	INFO
	WARNING
	ERROR
	FATAL
)

func (Level) Short

func (lvl Level) Short() string

Short returns a levels representation in log

func (Level) String

func (lvl Level) String() string

String implements the fmt.Stringer interface to allow use of levels in fmt calls.

type StyleFunction

type StyleFunction func(...interface{}) string

StyleFunction is a kind of function that is used for styling. I know, who would have thought.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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