logger

package
v0.0.0-...-1b30518 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package logger allows configurable, per-package logging.

Index

Constants

This section is empty.

Variables

View Source
var Context = func() string { return "" }

Context is a function returning a string that will be prepended to every log message, if defined. This can be used to insert timestamps, CPU info... The default does nothing and debug messages will be displayed as given.

View Source
var Enabled = make(map[string]bool)

Enabled setting controls whether logging will occur for a given module name when the usual methods are called. Default is no logging. Enabling 'all' will turn on debug output for every module.

View Source
var Level = Info // Sensible default

Level is the global log level above which nothing will be displayed.

View Source
var Levels = map[string]LogLevel{
	"fatal":     Fatal,
	"warning":   Warning,
	"info":      Info,
	"debug":     Debug,
	"desperate": Desperate,
}

Levels that can be specified on the command line.

View Source
var Loggers = make(map[string]*Logger)

Loggers is a registry of currently defined package-specific loggers.

Functions

func Help

func Help()

Help prints all registered loggers and sub-loggers so the user knows what can be enabled.

func HelpLevels

func HelpLevels()

HelpLevels lists the available log levels. Hardcoded in there because the order in which we put them in the Levels mapping is not guaranteed anyway. TODO: sort levels by enum value, auto-detect default based on Level value.

Types

type LogLevel

type LogLevel uint8

LogLevel representing the priority of a log message. An attempt to log a message whose LogLevel is above logger.Level will be silently ignored.

const (
	Fatal LogLevel = iota
	Warning
	Info
	Debug
	Desperate // The kind of level used in a Pixel FIFO, for instance...
)

Supported log levels.

type Logger

type Logger struct {
	Name string // Package or module name for this logger
	Help string // Help text to be displayed when calling with -debug help
	// contains filtered or unexported fields
}

Logger represents a name-based logger for "simple" debugging. Each package should register itself with logger, which will allow for a complete listing of all possible logger package/modules that can be used with the -debug flag.

func New

func New(name, help string) *Logger

New returns a Logger instance specific to the given package, after registering it with our base logger package so this logger and its modules can be listed from the command-line. Will panic if a logger with the same name is already defined.

func (*Logger) Add

func (l *Logger) Add(name, help string)

Add a sub-module to a package logger, which can then be enabled by using -debug <pkg>/<module> or -debug <pkg>/* on the command line.

func (*Logger) Debug

func (l *Logger) Debug(msg string)

Debug prints a message if the global log level is Debug or more.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, a ...interface{})

Debugf format-prints a message if the global log level is Debug or more.

func (*Logger) Desperate

func (l *Logger) Desperate(msg string)

Desperate prints a message if the global log level is the maximum.

func (*Logger) Desperatef

func (l *Logger) Desperatef(format string, a ...interface{})

Desperatef format-prints a message if the global log level is the maximum.

func (*Logger) Enabled

func (l *Logger) Enabled() bool

func (*Logger) Fatal

func (l *Logger) Fatal(msg string)

Fatal prints a message (then panics regardless of debug level).

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, a ...interface{})

Fatalf format-prints a message (then panics regardless of debug level).

func (*Logger) Info

func (l *Logger) Info(msg string)

Info prints a message if the global log level is Info (the default) or more.

func (*Logger) Infof

func (l *Logger) Infof(format string, a ...interface{})

Infof format-prints a message if the global log level is Info (the default) or more.

func (*Logger) Log

func (l *Logger) Log(msg string)

Log is an alias for Info.

func (*Logger) Logf

func (l *Logger) Logf(format string, a ...interface{})

Logf is an alias for Infof.

func (*Logger) String

func (l *Logger) String() string

String returns the description of a logger and all its sub-loggers if any.

func (*Logger) Sub

func (l *Logger) Sub(name string) *Logger

Sub returns a sub-module with the given name. If called with a module name that hasn't been registered with Add() first, returns the main logger. Otherwise, returns a Logger instance to allow chain call to print methods.

func (*Logger) Warning

func (l *Logger) Warning(msg string)

Warning prints a message if the global log level is Warning or more.

func (*Logger) Warningf

func (l *Logger) Warningf(format string, a ...interface{})

Warningf format-prints a message if the global log level is Warning or more.

Jump to

Keyboard shortcuts

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