Documentation
¶
Overview ¶
Package log provides a Logger primarily intended for terminal based command line programs.
The logs it produces are semi-structured with key value pairs being formatted as key=value but are primarily intended to be human readable and easy on the eye with a good choice of colours, ideal for command line applications that have a --debug or --verbose flag that enables extra logging.
log emphasis simplicity and efficiency so there aren't too many knobs to twiddle, you just get a consistent, easy to use, simple logger with minimal overhead.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithContext ¶ added in v0.2.0
WithContext stores the given logger in a context.Context.
The logger may be retrieved from the context with FromContext.
Types ¶
type Level ¶
type Level int
Level is a log level.
const ( // LevelDebug is the debug log level, intended for verbose logging modes or internal debugging. LevelDebug Level = -4 // LevelInfo is the info log level, this is the default level, intended for progress updates // and other informational messages. LevelInfo Level = 0 // LevelWarn is the warning log level, intended for raising recoverable issues to the user. Warning // logs should refer to events that are worth flagging to the user but the program can easily // recover from such as a missing configuration file when the application can fall back to defaults. LevelWarn Level = 4 // LevelError is the error log level. This is the highest log level provided by log and is intended // for signalling non-recoverable errors to the user. Typically followed by an actual go error and // possibly program exit. LevelError Level = 8 )
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a command line logger. It is safe to use across concurrently executing goroutines.
func FromContext ¶ added in v0.2.0
FromContext returns the Logger from a context.Context.
If the context does not contain a logger, a default logger is returned.
func New ¶
New returns a new Logger configured to write to w.
The logger can be configured by passing a number of functional options to set things like level, prefix etc.
func (*Logger) Prefixed ¶
Prefixed returns a new Logger with the given prefix.
The returned logger is otherwise an exact clone of the caller.
type Option ¶
type Option func(*Logger)
Option is a functional option for configuring a Logger.
func Prefix ¶
Prefix sets a prefix for the logger.
If set to a non-empty string, the prefix is shown on every log line prior to the message and any key value pairs.
func TimeFormat ¶
TimeFormat sets the format of the time information.
The layout is the standard Go time.Format and defaults to time.RFC3339.