Documentation
¶
Overview ¶
Package ultraviolet provides the main logging interface for Ultraviolet. Ultraviolet supports two environment variables — LOG_LEVELS and LOG.
LOG (separated by commas, supports wildcards) controls which log scopes are enabled. Subscopes are separated by the ScopeSeparator set in the logger (it's janky)
LOG_LEVELS (separated by commas) controls which log levels are enabled. The default levels are debug, info, warn, error, critical, all of which are on by default.
Index ¶
- Variables
- type Logger
- func (uv *Logger) Clone() *Logger
- func (uv *Logger) Critical(args ...any)
- func (uv *Logger) Debug(args ...any)
- func (uv *Logger) Error(args ...any)
- func (uv *Logger) Fatal(args ...any)
- func (uv *Logger) Info(args ...any)
- func (uv *Logger) Subscope(scope string) *Logger
- func (uv *Logger) Warn(args ...any)
- func (uv *Logger) WithLevel(level string, args ...any)
- type SimpleLogger
Constants ¶
This section is empty.
Variables ¶
var DefaultPrefixes = map[string]string{ "debug": clk.Gray("%s") + "(" + clk.Gray("?") + "):", "info": clk.BrightBlue("%s") + "(" + clk.BrightBlue("i") + "):", "warn": clk.WithBrightYellow().Bold("%s") + "(" + clk.WithBrightYellow().Bold("#") + "):", "error": clk.WithRed().Bold("%s") + "(" + clk.WithRed().Bold("!") + "):", "critical": clk.WithBrightMagenta().Bold("%s") + "(" + clk.WithBrightMagenta().Bold("CRITICAL") + "):", }
DefaultPrefixes is a map of the default prefixes in the library
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct {
// Whether the logger will print anything
Toggled bool
// The scope of the logger's messages, is inferred from
// the main module name by default.
Scope string
ThreadSafe bool // Makes ratelimiting thread-safe with `atomic` at the cost of performance
TimestampFormat string // Enables timestamps. Accepts Go's standard timestamp format.
TimestampIsUTC bool // Whether the timestamp should be in UTC
// Enables the ratelimiting feature.
RatelimitThroughput uint64 // The amount of messages allowed in a timeframe
RatelimitInterval uint64 // The desired timeframe divided by RatelimitThroughput (microseconds)
ScopeSeparator string // Separator between subscopes
// Prefixes for different log levels. The default log levels are:
// debug, info, warn, error, critical
// Custom log levels can also be added and used via uv.WithLevel()
Prefixes map[string]string
UnsignedFormat string // Format for unsigned integers
PIntFormat string // Format for positive integers
NIntFormat string // Format for negative integers
PFloatFormat string // Format for positive floats
NFloatFormat string // Format for negative floats
TrueFormat string // Format for 'true'
FalseFormat string // Format for 'false'
// Log levels that are displayed (default: empty, empty = all levels)
// The env variable LOG_LEVELS (separated by commas) overrides this
EnabledLevels []string
Output io.Writer // Stream to write to, os.Stderr by default
// This function runs after uv.Critical() or uv.Fatal() is called. Does nothing by default.
// The arguments are whatever was passed to Critical/Fatal
ExitFunction func(args ...any)
// This function is used to format complex objects such as maps and arrays.
// Uses pkg.go.dev/github.com/k0kubun/pp/v3 by default!
ObjectFormatter func(obj any) string
// contains filtered or unexported fields
}
Logger is the main logger structure. It can be cloned using uv.Clone() Note: "format" refers to the format used in Printf()
func ConvertSimple ¶
func ConvertSimple(simple *SimpleLogger) *Logger
ConvertSimple turns a SimpleLogger into a Logger.
func NewSimple ¶
func NewSimple() *Logger
NewSimple creates a logger with simplified default settings
func (*Logger) Subscope ¶
Subscope clones this logger and adds a subscope to it. If the logger's previous scope was inferred, it is replaced. Otherwise, it is appended using a separator from uv.ScopeSeparator
type SimpleLogger ¶
type SimpleLogger struct {
Prefixes map[string]string // Prefixes for different log levels
Scope string // Scope of the logger's messages
ScopeSeparator string // Separator between subscopes
FloatFormat string // Format for floats
IntegerFormat string // Format for integers
BooleanFormat string // Format for booleans
ExitFunction func(args ...any)
Output io.Writer
// contains filtered or unexported fields
}
SimpleLogger is a simplified version of Logger which can be converted using ConvertSimple(), check documentation for Logger for more detailed explanations
