Documentation ¶
Overview ¶
Package log based on https://en.wikipedia.org/wiki/ANSI_escape_code
Index ¶
- Constants
- Variables
- func ApplyStyles(message string, colors ...Style) string
- func Debug(v ...any)
- func Debugf(format string, v ...any)
- func Error(v ...any)
- func Errorf(format string, v ...any)
- func Fatal(v ...any)
- func Fatalf(format string, v ...any)
- func Info(v ...any)
- func Infof(format string, v ...any)
- func Output(calldepth int, level Level, v ...any)
- func Outputf(calldepth int, level Level, format string, v ...any)
- func Panic(v ...any)
- func Panicf(format string, v ...any)
- func SetDefault(logger *SimpleLogger)
- func SetFlags(flags int)
- func SetLevel(level Level)
- func SetLevelColor(level Level, color Style)
- func Trace(v ...any)
- func Tracef(format string, v ...any)
- func Warn(v ...any)
- func Warnf(format string, v ...any)
- type Level
- type Logger
- type SimpleLogger
- func (l *SimpleLogger) Debug(v ...any)
- func (l *SimpleLogger) Debugf(format string, v ...any)
- func (l *SimpleLogger) Error(v ...any)
- func (l *SimpleLogger) Errorf(format string, v ...any)
- func (l *SimpleLogger) Fatal(v ...any)
- func (l *SimpleLogger) Fatalf(format string, v ...any)
- func (l *SimpleLogger) Info(v ...any)
- func (l *SimpleLogger) Infof(format string, v ...any)
- func (l *SimpleLogger) Output(calldepth int, level Level, v ...any)
- func (l *SimpleLogger) Outputf(calldepth int, level Level, format string, v ...any)
- func (l *SimpleLogger) Panic(v ...any)
- func (l *SimpleLogger) Panicf(format string, v ...any)
- func (l *SimpleLogger) SetFlags(flags int)
- func (l *SimpleLogger) SetLevel(level Level)
- func (l *SimpleLogger) Trace(v ...any)
- func (l *SimpleLogger) Tracef(format string, v ...any)
- func (l *SimpleLogger) Warn(v ...any)
- func (l *SimpleLogger) Warnf(format string, v ...any)
- type Style
Constants ¶
const ( Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone Lmsgprefix // move the "prefix" from the beginning of the line to before the message LstdFlags = Ldate | Ltime // initial values for the standard logger )
These flags define which text to prefix to each Output entry generated by the Logger. Bits are or'ed together to control what's printed. Except the Lmsgprefix flag, there is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,
2009/01/23 01:23:23 message
while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,
2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message
Variables ¶
var ( EnableColors = true PrefixStyle = ForegroundColorBrightBlack LevelStyle = StyleBold TextStyle = ForegroundColorWhite )
var ( StyleReset = newInt(0) StyleBold = newInt(1) StyleFaint = newInt(2) StyleItalic = newInt(3) StyleUnderline = newInt(4) StyleSlowBlink = newInt(5) StyleRapidBlink = newInt(6) StyleInvert = newInt(7) StyleHide = newInt(8) StyleStrike = newInt(9) StyleDefaultFont = newInt(10) )
general Style(s)any
var ( StyleBlackLetterFont = newInt(20) StyleDoubleUnderlined = newInt(21) StyleNormalIntensity = newInt(22) StyleNeitherItalicNorBlackLetter = newInt(23) StyleNotUnderlined = newInt(24) StyleNotBlinking = newInt(25) StyleProportionalSpacing = newInt(26) StyleNotReversed = newInt(27) StyleReveal = newInt(28) StyleNotCrossedOut = newInt(29) )
more general Style(s)any
var ( ForegroundColorBlack = newInt(30) ForegroundColorRed = newInt(31) ForegroundColorGreen = newInt(32) ForegroundColorYellow = newInt(33) ForegroundColorBlue = newInt(34) ForegroundColorMagenta = newInt(35) ForegroundColorCyan = newInt(36) ForegroundColorWhite = newInt(37) )
foreground color Style(s)any
var ( DefaultForegroundColor = newInt(39) BackgroundColorBlack = newInt(40) BackgroundColorRed = newInt(41) BackgroundColorGreen = newInt(42) BackgroundColorYellow = newInt(43) BackgroundColorBlue = newInt(44) BackgroundColorMagenta = newInt(45) BackgroundColorCyan = newInt(46) BackgroundColorWhite = newInt(47) )
background color Style(s)any
var ( DefaultBackgroundColor = newInt(49) StyleDisableProportionalSpacing = newInt(50) StyleFramed = newInt(51) StyleEncircled = newInt(52) StyleOverlined = newInt(53) StyleNeitherFramedNorEncircled = newInt(54) StyleNotOverlined = newInt(55) )
more general Style(s)any
var ( StyleDefaultUnderlineColor = newInt(59) StyleIdeogramUnderlineOrRightSideLine = newInt(60) StyleIdeogramDoubleUnderlineOrDoubleLineOnRightSide = newInt(61) StyleIdeogramOverlineOrLeftSideLine = newInt(62) StyleIdeogramDoubleOverlineOrDoubleLineOnTheLeftSide = newInt(63) StyleIdeogramStressMarking = newInt(64) StyleNoIdeogramAttributes = newInt(65) )
more general Style(s)any
var ( StyleSuperscript = newInt(73) StyleSubscript = newInt(74) StyleNeitherSuperscriptNorSubscript = newInt(75) )
super/subscript Style(s)any
var ( ForegroundColorBrightBlack = newInt(90) ForegroundColorBrightRed = newInt(91) ForegroundColorBrightGreen = newInt(92) ForegroundColorBrightYellow = newInt(93) ForegroundColorBrightBlue = newInt(94) ForegroundColorBrightMagenta = newInt(95) ForegroundColorBrightCyan = newInt(96) ForegroundColorBrightWhite = newInt(97) )
foreground bright color Style(s)any
var ( BackgroundColorBrightBlack = newInt(100) BackgroundColorBrightRed = newInt(101) BackgroundColorBrightGreen = newInt(102) BackgroundColorBrightYellow = newInt(103) BackgroundColorBrightBlue = newInt(104) BackgroundColorBrightMagenta = newInt(105) BackgroundColorBrightCyan = newInt(106) BackgroundColorBrightWhite = newInt(107) )
background bright color Style(s)any
Functions ¶
func ApplyStyles ¶ added in v1.2.0
ApplyStyles wraps a given message in the given Style(s).
func Debug ¶ added in v1.2.0
func Debug(v ...any)
Debug logs on the LevelDebug with the default SimpleLogger
func Error ¶ added in v1.2.0
func Error(v ...any)
Error logs on the LevelError with the default SimpleLogger
func Fatal ¶ added in v1.2.0
func Fatal(v ...any)
Fatal logs on the LevelFatal with the default SimpleLogger
func Info ¶ added in v1.2.0
func Info(v ...any)
Info logs on the LevelInfo with the default SimpleLogger
func Panic ¶ added in v1.2.0
func Panic(v ...any)
Panic logs on the LevelPanic with the default SimpleLogger
func SetDefault ¶ added in v1.2.0
func SetDefault(logger *SimpleLogger)
SetDefault sets the default SimpleLogger
func SetFlags ¶ added in v1.2.0
func SetFlags(flags int)
SetFlags sets the Output flags like: Ldate, Ltime, Lmicroseconds, Llongfile, Lshortfile, LUTC, Lmsgprefix,LstdFlags of the default Logger
func SetLevel ¶ added in v1.2.0
func SetLevel(level Level)
SetLevel sets the Level of the default Logger
func SetLevelColor ¶ added in v1.2.0
SetLevelColor sets the Style of the given Level
func Trace ¶ added in v1.2.0
func Trace(v ...any)
Trace logs on the LevelTrace with the default SimpleLogger
Types ¶
type Level ¶ added in v1.2.0
type Level int
Level are different levels at which the SimpleLogger can Output
All Level(s) which SimpleLogger supports
type Logger ¶
type Logger interface { Trace(args ...any) Debug(args ...any) Info(args ...any) Warn(args ...any) Error(args ...any) Fatal(args ...any) Panic(args ...any) Tracef(format string, args ...any) Debugf(format string, args ...any) Infof(format string, args ...any) Warnf(format string, args ...any) Errorf(format string, args ...any) Fatalf(format string, args ...any) Panicf(format string, args ...any) }
Logger is the logging interface you can implement/use
type SimpleLogger ¶ added in v1.2.0
type SimpleLogger struct {
// contains filtered or unexported fields
}
SimpleLogger is a wrapper for the std Logger
func Default ¶ added in v1.2.0
func Default() *SimpleLogger
Default returns the default SimpleLogger
func New ¶ added in v1.2.0
func New(flags int) *SimpleLogger
New returns a newInt SimpleLogger implementation
func (*SimpleLogger) Debug ¶ added in v1.2.0
func (l *SimpleLogger) Debug(v ...any)
Debug logs on the LevelDebug
func (*SimpleLogger) Debugf ¶ added in v1.2.0
func (l *SimpleLogger) Debugf(format string, v ...any)
Debugf logs on the LevelDebug
func (*SimpleLogger) Error ¶ added in v1.2.0
func (l *SimpleLogger) Error(v ...any)
Error logs on the LevelError
func (*SimpleLogger) Errorf ¶ added in v1.2.0
func (l *SimpleLogger) Errorf(format string, v ...any)
Errorf logs on the LevelError
func (*SimpleLogger) Fatal ¶ added in v1.2.0
func (l *SimpleLogger) Fatal(v ...any)
Fatal logs on the LevelFatal
func (*SimpleLogger) Fatalf ¶ added in v1.2.0
func (l *SimpleLogger) Fatalf(format string, v ...any)
Fatalf logs on the LevelFatal
func (*SimpleLogger) Info ¶ added in v1.2.0
func (l *SimpleLogger) Info(v ...any)
Info logs on the LevelInfo
func (*SimpleLogger) Infof ¶ added in v1.2.0
func (l *SimpleLogger) Infof(format string, v ...any)
Infof logs on the LevelInfo
func (*SimpleLogger) Output ¶ added in v1.2.0
func (l *SimpleLogger) Output(calldepth int, level Level, v ...any)
func (*SimpleLogger) Outputf ¶ added in v1.2.0
func (l *SimpleLogger) Outputf(calldepth int, level Level, format string, v ...any)
func (*SimpleLogger) Panic ¶ added in v1.2.0
func (l *SimpleLogger) Panic(v ...any)
Panic logs on the LevelPanic
func (*SimpleLogger) Panicf ¶ added in v1.2.0
func (l *SimpleLogger) Panicf(format string, v ...any)
Panicf logs on the LevelPanic
func (*SimpleLogger) SetFlags ¶ added in v1.2.0
func (l *SimpleLogger) SetFlags(flags int)
SetFlags sets the Output flags like: Ldate, Ltime, Lmicroseconds, Llongfile, Lshortfile, LUTC, Lmsgprefix,LstdFlags
func (*SimpleLogger) SetLevel ¶ added in v1.2.0
func (l *SimpleLogger) SetLevel(level Level)
SetLevel sets the lowest Level to Output for
func (*SimpleLogger) Trace ¶ added in v1.2.0
func (l *SimpleLogger) Trace(v ...any)
Trace logs on the LevelTrace
func (*SimpleLogger) Tracef ¶ added in v1.2.0
func (l *SimpleLogger) Tracef(format string, v ...any)
Tracef logs on the LevelTrace
func (*SimpleLogger) Warn ¶ added in v1.2.0
func (l *SimpleLogger) Warn(v ...any)
Warn logs on the LevelWarn
func (*SimpleLogger) Warnf ¶ added in v1.2.0
func (l *SimpleLogger) Warnf(format string, v ...any)
Warnf logs on the LevelWarn
type Style ¶ added in v1.2.0
type Style string
Style represents a text
func AlternateFont ¶ added in v1.2.0
AlternateFont returns a Style which alternates the font
func SetBackgroundColor ¶ added in v1.2.0
SetBackgroundColor returns a Style which sets the background color
func SetForegroundColor ¶ added in v1.2.0
SetForegroundColor returns a Style which sets the foreground color
func SetUnderlineColor ¶ added in v1.2.0
SetUnderlineColor returns a Style which sets the underline color
func (Style) ApplyClear ¶ added in v1.2.0
ApplyClear applies a given Style to the given text with clearing all Style(s) before