Documentation ¶
Index ¶
- Constants
- Variables
- func HexColor(hex string) string
- type Config
- type FileTee
- type Logger
- func (l *Logger) Configure(cfg *Config)
- func (l *Logger) Debug(tmpl string, args ...interface{})
- func (l *Logger) Error(tmpl string, args ...interface{})
- func (l *Logger) Fatal(tmpl string, args ...interface{})
- func (l *Logger) Format(level logLevel, tmpl string, args ...interface{}) string
- func (l *Logger) Info(tmpl string, args ...interface{})
- func (l *Logger) Warn(tmpl string, args ...interface{})
- type Theme
- type ThemeColor
Constants ¶
const ( // NoColor doesn't use any color codes at all (plain text). NoColor colorLevel = iota // ANSIColor uses the standard 16 colors supported by most terminals. This // option is the most portable across platforms. ANSIColor // ExtendedColor allows the use of 256 colors supported by most modern // terminals (24-bit color codes). ExtendedColor )
Options for color support in your logger.
const ( // DefaultFormat: shows the date in the secondary (dark) color, the label // in the bright color, and the message text in the normal color. DefaultFormat = `{{.Secondary}}{{.Time}}{{.Reset}} {{.Primary}}[{{.Level}}]{{.Reset}} {{.Message}}` // ColorfulFormat: like the DefaultFormat, but the message itself is also // colored using the secondary color. ColorfulFormat = `{{.Secondary}}{{.Time}}{{.Reset}} {{.Primary}}[{{.Level}}]{{.Reset}} {{.Secondary}}{{.Message}}{{.Reset}}` )
Convenient log formats to use in your logger.
const ( // DefaultTime is the default, in `yyyy-mm-dd hh:mm:ss` format. DefaultTime = `2006-01-02 15:04:05` // FriendlyTime is a human readable `Jan 2 15:04:05 2006` format. FriendlyTime = `Jan 2 15:04:05 2006` )
Convenient time formats to use in your logger.
const ( DebugLevel logLevel = iota InfoLevel WarnLevel ErrorLevel FatalLevel )
Log levels for controlling whether or not logs of certain types will be emitted by your logger.
Variables ¶
var DarkTheme = Theme{ Debug: ThemeColor{ansi.BrightCyan, HexColor("#FF99FF")}, DebugSecondary: ThemeColor{ansi.Cyan, HexColor("#996699")}, Info: ThemeColor{ansi.BrightGreen, HexColor("#0099FF")}, InfoSecondary: ThemeColor{ansi.Green, HexColor("#006699")}, Warn: ThemeColor{ansi.BrightYellow, HexColor("#FF9900")}, WarnSecondary: ThemeColor{ansi.Yellow, HexColor("#996600")}, Error: ThemeColor{ansi.BrightRed, HexColor("#FF0000")}, ErrorSecondary: ThemeColor{ansi.Red, HexColor("#CC0000")}, }
DarkTheme is a suitable default theme for dark terminal backgrounds.
var RegexpANSIColorCode = regexp.MustCompile(`\x1B\[[0-9;]+m`)
Functions ¶
Types ¶
type Config ¶
type Config struct { // Level is one of DebugLevel, InfoLevel, WarnLevel, ErrorLevel or FatalLevel. // Messages emitted by the logger must be 'at least' this level to be logged. Level logLevel // What colors are supported? Default is NoColor. Use ANSIColor to support // legacy terminal emulators, or ExtendedColor for modern 256-color support. Colors colorLevel // Which color theme are you using? The default is DarkTheme. Theme Theme // Where to write the log messages to? If not defined with a custom io.Writer, // the default goes to standard output for Debug and Info messages and // standard error for warnings, errors, and fatal messages. Writer io.Writer // How do you want to format your log lines? This should be a Go text format // string, with the following variable placeholders: // // {{.Time}} inserts the date/time stamp for the log message. // {{.Level}} inserts a label for the log level, e.g. "INFO" or "WARN" // {{.Message}} inserts the text of the log message itself. // {{.Primary}} inserts the color sequence for the primary color based // on the log level for the message. // {{.Secondary}} inserts the color sequence for the secondary color. // {{.Reset}} inserts the 'reset' color sequence to stop coloring // the rest of the text that follows. // // The default log format is as follows: // // {{.Secondary}}{{.Time}}{{.Reset}} {{.Primary}}[{{.Level}}]{{.Reset}} {{.Message}} Format string // How do you want to format your time stamps? (The `{{.Time}}`). This uses // the Go `time` module, so the TimeFormat should use their reference date/time. // The default TimeFormat is: `2006-01-02 15:04:05` TimeFormat string }
Config stores settings that control the logger's behavior.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with the default values filled in.
type FileTee ¶
type FileTee struct {
// contains filtered or unexported fields
}
FileTee can write logs to a file on disk as well as standard output.
func NewFileTee ¶
type Logger ¶
Logger stores the configuration for a named logger instance.
func (*Logger) Configure ¶
Configure applies the configuration to the logger. If any of the following keys are not defined (or have zero-values), the default value for the key will be used instead:
Format TimeFormat
type Theme ¶
type Theme struct { Debug ThemeColor DebugSecondary ThemeColor Info ThemeColor InfoSecondary ThemeColor Warn ThemeColor WarnSecondary ThemeColor Error ThemeColor ErrorSecondary ThemeColor }
Theme defines the color scheme for a logger. Each log level has two colors: a primary (for the label itself) and a secondary color. For example, if your log lines include a date/time this could be colored using the secondary color.
type ThemeColor ¶
ThemeColor defines a color tuple for ANSI (legacy) support and modern 256-color support.