log

package
v1.10.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package log provides access to log functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Tokens is a map of the tokens that can be used in Format
	// to insert values returned by the execution of a callback.
	Tokens = map[string]func() string{
		"{date}": func() string {
			return time.Now().Format(DateFormat)
		},
		"{time}": func() string {
			return time.Now().Format(TimeFormat)
		},
		"{datetime}": func() string {
			return time.Now().Format(DateTimeFormat)
		},
		"{level:value}": func() string {
			return strconv.Itoa(int(currLevel))
		},
		"{level:name}": func() string {
			return LevelNames[currLevel]
		},
		"{level:color}": func() string {
			return LevelColors[currLevel]
		},
		"{message}": func() string {
			return currMessage
		},
	}
	// Effects is a map of the tokens that can be used in Format to
	// change the properties of the text.
	Effects = map[string]string{
		"{bold}":        tui.BOLD,
		"{dim}":         tui.DIM,
		"{red}":         tui.RED,
		"{green}":       tui.GREEN,
		"{blue}":        tui.BLUE,
		"{yellow}":      tui.YELLOW,
		"{f:black}":     tui.FOREBLACK,
		"{f:white}":     tui.FOREWHITE,
		"{b:darkgray}":  tui.BACKDARKGRAY,
		"{b:red}":       tui.BACKRED,
		"{b:green}":     tui.BACKGREEN,
		"{b:yellow}":    tui.BACKYELLOW,
		"{b:lightblue}": tui.BACKLIGHTBLUE,
		"{reset}":       tui.RESET,
	}
	// DateFormat is the default date format being used when filling the {date} log token.
	DateFormat = "06-Jan-02"
	// TimeFormat is the default time format being used when filling the {time} or {datetime} log tokens.
	TimeFormat = "15:04:05"
	// DateTimeFormat is the default date and time format being used when filling the {datetime} log token.
	DateTimeFormat = "2006-01-02 15:04:05"
	// Format is the default format being used when logging.
	Format = "{datetime} {level:color}{level:name}{reset} {message}"
)
View Source
var (
	// LevelNames is a map of the names ( {level:name} ) of each verbosity level.
	LevelNames = map[Verbosity]string{
		DEBUG:     "dbg",
		INFO:      "inf",
		IMPORTANT: "imp",
		WARNING:   "war",
		ERROR:     "err",
		FATAL:     "!!!",
	}
	// LevelColors is a map of the colors ( {level:color} ) of each verbosity level.
	LevelColors = map[Verbosity]string{
		DEBUG:     tui.DIM + tui.FOREBLACK + tui.BACKDARKGRAY,
		INFO:      tui.FOREWHITE + tui.BACKGREEN,
		IMPORTANT: tui.FOREWHITE + tui.BACKLIGHTBLUE,
		WARNING:   tui.FOREWHITE + tui.BACKYELLOW,
		ERROR:     tui.FOREWHITE + tui.BACKRED,
		FATAL:     tui.FOREWHITE + tui.BACKRED + tui.BOLD,
	}
)
View Source
var (
	// Level represents the current verbosity level of the logging system.
	Level = INFO
	// Output represents the log output file path if filled or, if empty, stdout.
	Output = ""
	// NoEffects disables all effects and colors if set to true.
	NoEffects = false
	// OnFatal represents the callback/action to execute on Fatal messages.
	OnFatal = ExitOnFatal
)

Functions

func Close

func Close()

Close finalizes the logging system.

func Debug

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

Debug emits a debug message.

func Error

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

Error emits an error message.

func ExitCleanOnFatal

func ExitCleanOnFatal()

os.Exit(0) on Fatal messages.

func ExitOnFatal

func ExitOnFatal()

os.Exit(1) on Fatal messages.

func Fatal

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

Fatal emits a fatal error message and calls the log.OnFatal callback.

func Important

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

Important emits an important informative message.

func Info

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

Info emits an informative message.

func LevelColor added in v1.3.0

func LevelColor(v Verbosity) string

LevelColor returns the color of a verbosity level or "" if effects are disabled.

func LevelName added in v1.3.0

func LevelName(v Verbosity) string

LevelName returns the name of a verbosity level.

func NoneOnFatal

func NoneOnFatal()

Do nothing on Fatal messages.

func Open

func Open() (err error)

Open initializes the logging system.

func Raw added in v1.1.1

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

Raw emits a message without format to the logs.

func Warning

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

Warning emits a warning message.

Types

type FatalPolicy

type FatalPolicy func()

FatalPolicy represents a callback to be executed on Fatal messages.

type Verbosity

type Verbosity int

Verbosity represents the verbosity level of the logger.

const (
	// Debug messages.
	DEBUG Verbosity = iota
	// Informative messages.
	INFO
	// Informative messages that are important.
	IMPORTANT
	// Warning messages.
	WARNING
	// Recoverable error conditions.
	ERROR
	// Fatal error conditions.
	FATAL
)

Jump to

Keyboard shortcuts

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