Documentation
¶
Overview ¶
Package bea provides structured logging with customizable formatters and transports, context propagation, child loggers, sensitive-field redaction, fallback delivery, and panic recovery at transport boundaries. It is the Go port of the npm package @rickferrdevelop/bea-logger.
Create a logger with NewDefault for colored console output, or use New to select a formatter and one or more transports. Logging methods return errors to the caller; Fatal records a fatal-level entry but does not exit the process. Context-aware variants forward cancellation and deadlines to every transport.
Index ¶
- Variables
- func ContextToString(context map[string]any) string
- func FieldToContext(fields []Field) map[string]any
- func Style(text string, colors ...Color) string
- type Color
- type ContextColorOverrides
- type ContextColors
- type CustomFormatterOptions
- type Data
- type Field
- type FileTransportOptions
- type Formatter
- type Level
- type LevelColorOverrides
- type LevelColors
- type LogColorOverrides
- type Logger
- func (logger *Logger) Child(fields ...Field) *Logger
- func (logger *Logger) Debug(message string, fields ...Field) error
- func (logger *Logger) DebugContext(ctx context.Context, message string, fields ...Field) error
- func (logger *Logger) Error(message string, fields ...Field) error
- func (logger *Logger) ErrorContext(ctx context.Context, message string, fields ...Field) error
- func (logger *Logger) Fatal(message string, fields ...Field) error
- func (logger *Logger) FatalContext(ctx context.Context, message string, fields ...Field) error
- func (logger *Logger) Handler(data Data) error
- func (logger *Logger) HandlerContext(ctx context.Context, data Data) error
- func (logger *Logger) Info(message string, fields ...Field) error
- func (logger *Logger) InfoContext(ctx context.Context, message string, fields ...Field) error
- func (logger *Logger) Warn(message string, fields ...Field) error
- func (logger *Logger) WarnContext(ctx context.Context, message string, fields ...Field) error
- type M
- type Option
- type Options
- type PaletteColors
- type PaletteName
- type Transport
- type TransportPanicError
Constants ¶
This section is empty.
Variables ¶
View Source
var ( FormatSimple = Simple() FormatJson = Json() FormatPretty = Pretty(Classic) FormatPrettyClassic = FormatPretty FormatPrettyVibrant = Pretty(Vibrant) FormatPrettySoft = Pretty(Soft) FormatPrettyMonochrome = Pretty(Monochrome) FormatVerbose = Verbose() )
View Source
var ( ClassicColors = PaletteColors{ Info: classicLevel(Blue), Warn: classicLevel(Yellow), Error: classicLevel(Red), Fatal: classicLevel(Magenta), Debug: { Level: []Color{Dim, Bold}, Brackets: []Color{Dim}, Message: []Color{Gray}, Separator: []Color{Dim}, Context: dimContext(), }, } VibrantColors = createPalette( map[Level]Color{Info: Cyan, Warn: Yellow, Error: Red, Fatal: Magenta, Debug: Green}, []Color{Bold}, []Color{White}, ) SoftColors = createPalette( map[Level]Color{Info: Blue, Warn: Yellow, Error: Red, Fatal: Magenta, Debug: Cyan}, []Color{Dim}, []Color{Gray}, ) MonochromeColors = createPalette( map[Level]Color{Info: White, Warn: White, Error: White, Fatal: White, Debug: Gray}, []Color{Bold}, []Color{Dim}, ) Palettes = map[PaletteName]PaletteColors{ Classic: ClassicColors, Vibrant: VibrantColors, Soft: SoftColors, Monochrome: MonochromeColors, } )
View Source
var (
ConsoleTransport = []Transport{Console()}
)
Functions ¶
func ContextToString ¶
func FieldToContext ¶
Types ¶
type ContextColorOverrides ¶
type ContextColors ¶
type CustomFormatterOptions ¶
type CustomFormatterOptions struct {
Palette PaletteName
Pretty LogColorOverrides
}
type FileTransportOptions ¶
type Formatter ¶
func Custom ¶
func Custom(options CustomFormatterOptions) Formatter
func Pretty ¶
func Pretty(variant PaletteName) Formatter
type LevelColorOverrides ¶
type LevelColorOverrides struct {
Level []Color
Brackets []Color
Message []Color
Separator []Color
Context ContextColorOverrides
}
type LevelColors ¶
type LevelColors struct {
Level []Color
Brackets []Color
Message []Color
Separator []Color
Context ContextColors
}
type LogColorOverrides ¶
type LogColorOverrides map[Level]LevelColorOverrides
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewDefault ¶
func (*Logger) DebugContext ¶
func (*Logger) ErrorContext ¶
func (*Logger) FatalContext ¶
func (*Logger) HandlerContext ¶
func (*Logger) InfoContext ¶
type PaletteColors ¶
type PaletteColors map[Level]LevelColors
type PaletteName ¶
type PaletteName string
const ( Classic PaletteName = "classic" Vibrant PaletteName = "vibrant" Soft PaletteName = "soft" Monochrome PaletteName = "monochrome" )
type Transport ¶
func File ¶
func File(options FileTransportOptions) Transport
func RecoverTransport ¶
type TransportPanicError ¶
func (*TransportPanicError) Error ¶
func (e *TransportPanicError) Error() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.