Documentation
¶
Index ¶
- Variables
- type AnsiBackgroundColor
- type AnsiColor
- func (ac AnsiColor) Bold() AnsiColor
- func (ac AnsiColor) Colorize(str string) string
- func (ac AnsiColor) Dim() AnsiColor
- func (ac AnsiColor) Italic() AnsiColor
- func (ac AnsiColor) SetBackground(background AnsiBackgroundColor) AnsiColor
- func (ac AnsiColor) SlowBlink() AnsiColor
- func (ac AnsiColor) Underline() AnsiColor
- type Bracket
- type Color
- type ColorizedFormatter
- type Field
- type FieldDateTime
- type FieldLevel
- type FieldPrinterFunc
- type FieldTag
- type FileNotFoundError
- type Formatter
- type Level
- type LevelParsingError
- type Logger
- type LoggerInitializationError
- type LoggerOption
- func WithColorization(colorize bool) LoggerOption
- func WithDestination(writer io.Writer) LoggerOption
- func WithFallbackEnabled(fallback bool) LoggerOption
- func WithFormatter(formatter Formatter) LoggerOption
- func WithLevelColors(colors map[Level]Color) LoggerOption
- func WithMinLevel(level Level) LoggerOption
- func WithPanicOnPanicLevel(panicOnPanicLevel bool) LoggerOption
- func WithPrefixFields(fields ...Field) LoggerOption
- func WithSilent(silent bool) LoggerOption
- func WithSuffixFields(fields ...Field) LoggerOption
- type PrintArgs
- type SimpleBracket
- type TagFieldOpt
- type TagPadSettings
Constants ¶
This section is empty.
Variables ¶
var AnsiBold = ansiSetting("1")
var AnsiDim = ansiSetting("2")
var AnsiItalic = ansiSetting("3")
var AnsiSlowBlink = ansiSetting("5")
var AnsiStrikethrough = ansiSetting("9")
var AnsiUnderline = ansiSetting("4")
var BackgroundBlack = AnsiBackgroundColor("40")
var BackgroundBlue = AnsiBackgroundColor("44")
var BackgroundCyan = AnsiBackgroundColor("46")
var BackgroundGreen = AnsiBackgroundColor("42")
var BackgroundMagenta = AnsiBackgroundColor("45")
var BackgroundRed = AnsiBackgroundColor("41")
var BackgroundWhite = AnsiBackgroundColor("47")
var BackgroundYellow = AnsiBackgroundColor("43")
var BracketAngle = SimpleBracket{"<", ">"}
var BracketCurly = SimpleBracket{"{", "}"}
var BracketNone = SimpleBracket{"", ""}
var BracketRound = SimpleBracket{"(", ")"}
var BracketSquare = SimpleBracket{"[", "]"}
var ColorBlue = AnsiColor{/* contains filtered or unexported fields */}
var ColorCyan = AnsiColor{/* contains filtered or unexported fields */}
var ColorDefault = AnsiColor{/* contains filtered or unexported fields */}
var ColorGreen = AnsiColor{/* contains filtered or unexported fields */}
var ColorMagenta = AnsiColor{/* contains filtered or unexported fields */}
var ColorRed = AnsiColor{/* contains filtered or unexported fields */}
var ColorWhite = AnsiColor{/* contains filtered or unexported fields */}
var ColorYellow = AnsiColor{/* contains filtered or unexported fields */}
var ColorizationNotSupportedError = errors.New("formatter does not support colorization")
var FileNotSpecifiedError = errors.New("filename not provided to NewFileLogger")
Functions ¶
This section is empty.
Types ¶
type AnsiBackgroundColor ¶
type AnsiBackgroundColor = []byte
func BackgroundRGB ¶
func BackgroundRGB(r, g, b int) AnsiBackgroundColor
type AnsiColor ¶
type AnsiColor struct {
// contains filtered or unexported fields
}
func (AnsiColor) Colorize ¶
TODO: Benchmark different ways of doing this. Went for the single buffer approach for now.
func (AnsiColor) SetBackground ¶
func (ac AnsiColor) SetBackground(background AnsiBackgroundColor) AnsiColor
type ColorizedFormatter ¶
type ColorizedFormatter interface { Formatter EnableColorization(colorize bool) error SetLevelColors(colors map[Level]Color) error }
func NewColorizedFormatter ¶
func NewColorizedFormatter( prefixFields []Field, suffixFields []Field, enableColor bool, ) (ColorizedFormatter, error)
type Field ¶
type Field interface {
FieldPrinter() (FieldPrinterFunc, error)
}
type FieldDateTime ¶
type FieldDateTime struct {
// contains filtered or unexported fields
}
func NewDateTimeField ¶
func NewDateTimeField(dateTimeFormat string) *FieldDateTime
func (*FieldDateTime) FieldPrinter ¶
func (f *FieldDateTime) FieldPrinter() (FieldPrinterFunc, error)
func (*FieldDateTime) SetDateTimeFormat ¶
func (f *FieldDateTime) SetDateTimeFormat(format string) Field
type FieldLevel ¶
type FieldLevel struct {
// contains filtered or unexported fields
}
func NewLevelField ¶
func NewLevelField(bracket Bracket) *FieldLevel
func (*FieldLevel) FieldPrinter ¶
func (f *FieldLevel) FieldPrinter() (FieldPrinterFunc, error)
type FieldPrinterFunc ¶
type FieldTag ¶
type FieldTag struct {
// contains filtered or unexported fields
}
func NewTagField ¶
func NewTagField(tag string, opts ...TagFieldOpt) *FieldTag
func (*FieldTag) FieldPrinter ¶
func (f *FieldTag) FieldPrinter() (FieldPrinterFunc, error)
type FileNotFoundError ¶
type FileNotFoundError struct {
// contains filtered or unexported fields
}
func (*FileNotFoundError) Error ¶
func (e *FileNotFoundError) Error() string
type Level ¶
type Level int
Level is a type representing the level of a log message.
It can be one of the following:
- Debug
- Info
- Warn
- Error
- Panic
Levels determine the priority of a log message, and can be hidden if a logger's minimum level is set to a higher level than the message's level.
For example, if a logger's minimum level is set to Warn, then a message with a level of Info will not be written to the output.
func ParseLevel ¶
ParseLevel parses a string into a Level. Returns an error if the string is not a valid Level.
type LevelParsingError ¶
type LevelParsingError struct {
// contains filtered or unexported fields
}
func (*LevelParsingError) Error ¶
func (e *LevelParsingError) Error() string
type Logger ¶
type Logger interface { // Log logs at the specified level without formatting. Log(level Level, msg string) // Logf logs at the specified level with formatted message. Logf(level Level, format string, args ...any) // Debug logs a debug-level message. Debug(msg string) // Debugf logs a debug-level message with formatting. Debugf(format string, args ...any) // Info logs an info-level message. Info(msg string) // Infof logs an info-level message with formatting. Infof(format string, args ...any) // Warn logs a warning-level message. Warn(msg string) // Warnf logs a warning-level message with formatting. Warnf(format string, args ...any) // Error logs an error-level message. Error(msg string) // Errorf logs an error-level message with formatting. Errorf(format string, args ...any) // Panic logs a panic-level message and then panics. Panic(msg string) // Panicf logs a panic-level message with formatting and then panics. Panicf(format string, args ...any) // Slog returns the string representation of a log message with the given level and message. Slog(level Level, msg string) string // Slogf returns the string representation of a formatted log message with the given level and sprint string. Slogf(level Level, format string, args ...any) string // Slogln returns the string representation of a log message with the given level and message, followed by a newline. Slogln(level Level, msg string) string // SetMinLevel sets the minimum logging level that will be output. SetMinLevel(level Level) }
Logger defines the interface for a structured ultraLogger in Go.
This interface is useful for either creating your own logger or for using an existing logger, and preventing changes to the loggers formatting settings.
func NewFileLogger ¶
NewFileLogger returns a new Logger that writes to a file.
If the filename is empty, FileNotSpecifiedError is returned. If the file does not exist, FileNotFoundError is returned.
func NewLogger ¶
func NewLogger(opts ...LoggerOption) (Logger, error)
NewLogger returns a new Logger that writes to stdout
type LoggerInitializationError ¶
type LoggerInitializationError struct {
// contains filtered or unexported fields
}
func (*LoggerInitializationError) Error ¶
func (e *LoggerInitializationError) Error() string
type LoggerOption ¶
type LoggerOption func(l *ultraLogger) error
func WithColorization ¶
func WithColorization(colorize bool) LoggerOption
func WithDestination ¶
func WithDestination(writer io.Writer) LoggerOption
func WithFallbackEnabled ¶
func WithFallbackEnabled(fallback bool) LoggerOption
func WithFormatter ¶
func WithFormatter(formatter Formatter) LoggerOption
func WithLevelColors ¶
func WithLevelColors(colors map[Level]Color) LoggerOption
func WithMinLevel ¶
func WithMinLevel(level Level) LoggerOption
func WithPanicOnPanicLevel ¶
func WithPanicOnPanicLevel(panicOnPanicLevel bool) LoggerOption
func WithPrefixFields ¶
func WithPrefixFields(fields ...Field) LoggerOption
func WithSilent ¶
func WithSilent(silent bool) LoggerOption
func WithSuffixFields ¶
func WithSuffixFields(fields ...Field) LoggerOption
type SimpleBracket ¶
type SimpleBracket struct {
// contains filtered or unexported fields
}
func (SimpleBracket) Close ¶
func (sb SimpleBracket) Close() string
func (SimpleBracket) Open ¶
func (sb SimpleBracket) Open() string
func (SimpleBracket) Wrap ¶
func (sb SimpleBracket) Wrap(content string) string
type TagFieldOpt ¶
type TagFieldOpt func(tf *FieldTag)
func WithBracket ¶
func WithBracket(bracket Bracket) TagFieldOpt
func WithPadChar ¶
func WithPadChar(padChar string) TagFieldOpt
func WithPadSettings ¶
func WithPadSettings(padSettings TagPadSettings) TagFieldOpt
func WithPrefixPadSize ¶
func WithPrefixPadSize(prefixPadSize int) TagFieldOpt
func WithSuffixPadSize ¶
func WithSuffixPadSize(suffixPadSize int) TagFieldOpt