Documentation
¶
Index ¶
- Constants
- func AddWriter(w io.Writer, configs ...WriterConfigModifier) (stop func())
- func Debug(v ...any) string
- func Debugf(msg string, v ...any) string
- func Error(v ...any) string
- func Errorf(msg string, v ...any) string
- func FormatDefault(m *Message) []byte
- func FormatJSON(m *Message) []byte
- func FormatWithColours(m *Message) []byte
- func Info(v ...any) string
- func Infof(msg string, v ...any) string
- func Panic(v ...any)
- func Panicf(msg string, v ...any)
- func SetBufferSize(size int)
- func SetMeta(data map[string]any)
- func Success(v ...any) string
- func Successf(msg string, v ...any) string
- func Wait(opts ...WaitOption) bool
- func Warn(v ...any) string
- func Warnf(msg string, v ...any) string
- type Formatter
- type Interfaces
- type Logger
- type Logr
- func (l *Logr) Debug(v ...any) string
- func (l *Logr) Debugf(msg string, v ...any) string
- func (l *Logr) Error(v ...any) string
- func (l *Logr) Errorf(msg string, v ...any) string
- func (l *Logr) Info(v ...any) string
- func (l *Logr) Infof(msg string, v ...any) string
- func (l *Logr) Panic(v ...any)
- func (l *Logr) Panicf(msg string, v ...any)
- func (l *Logr) Success(v ...any) string
- func (l *Logr) Successf(msg string, v ...any) string
- func (l *Logr) Warn(v ...any) string
- func (l *Logr) Warnf(msg string, v ...any) string
- func (l *Logr) With(data Meta) Logger
- type Message
- type Meta
- type MetaData
- type Type
- type WaitOption
- type WriterConfig
- type WriterConfigModifier
Examples ¶
Constants ¶
const ( None Type = iota // None P Type = 1 << iota // Panic E // Error W // Warning I // Info D // Debug S // Success Critical = P | E Monitor = Critical | W Verbose = Monitor | I | S All = Verbose | D )
Available log types
const (
// ColourReset code
ColourReset = "\x1B[0m"
)
Variables ¶
This section is empty.
Functions ¶
func AddWriter ¶
func AddWriter(w io.Writer, configs ...WriterConfigModifier) (stop func())
AddWriter add a io.Writer to the collection of writers that store the log messages.
Example ¶
AddWriter(os.Stdout) // which is equivalent to // AddWriter(os.Stdout, WithFormatter(FormatDefault), WithFilter(All))
func FormatDefault ¶
LogrFormat is a Formatter that converts a Message to a default format.
func FormatJSON ¶
FormatJSON is a Formatter that converts a Message to json
func FormatWithColours ¶
FormatWithColours is a Formatter that converts a Message to a colourful default format.
Example ¶
AddWriter(os.Stdout, WithFormatter(FormatWithColours))
func SetBufferSize ¶
func SetBufferSize(size int)
SetBufferSize updates the message queue buffer size. Default size is 10,000 (10K)
func Wait ¶
func Wait(opts ...WaitOption) bool
Wait for log messages to be processed. Returns true when all messages are processed. Optional WaitOption can be provided to set a timeout or context. Without options, Wait blocks until all pending messages are processed. Returns false if the timeout or context was cancelled before all messages were processed.
Types ¶
type Formatter ¶
Formatter is a function that returns a formatted byte array representation of the given Message.
type Interfaces ¶
type Interfaces []any
func (Interfaces) SSV ¶
func (i Interfaces) SSV() string
SSV creates a space separated values string
func (Interfaces) Strings ¶
func (i Interfaces) Strings() []string
type Logger ¶
type Logger interface {
Panic(v ...any)
Panicf(msg string, v ...any)
Error(v ...any) string
Errorf(msg string, v ...any) string
Warn(v ...any) string
Warnf(msg string, v ...any) string
Info(v ...any) string
Infof(msg string, v ...any) string
Debug(v ...any) string
Debugf(msg string, v ...any) string
Success(v ...any) string
Successf(msg string, v ...any) string
With(data Meta) Logger
}
Logger defines the methods available both by the logr package and Logr containing additional meta data.
type Logr ¶
type Logr struct {
// contains filtered or unexported fields
}
Logr implements the Logger interface
type Message ¶
type Message struct {
Type Type `json:"type"`
Time string `json:"time"`
Code string `json:"code"`
Desc string `json:"description"`
Meta MetaData `json:"metadata,omitempty"`
// contains filtered or unexported fields
}
Message used to send log message to logger goroutine
type Type ¶
type Type int
Type of log item
func LabelToType ¶
LabelToType converts a label to a log type/level Available labels are one of: none, panic, error, warning, info, success, debug, critical, monitor, verbose, all If the label is not found, it defaults to error and logs a message explaining the cause
Example ¶
// available labels:
// none // -
// panic // Panic
// error // Panic, Error
// warning // Panic, Error, Warning
// info // Panic, Error, Warning, Info
// success // Panic, Error, Warning, Info, Success
// debug // Panic, Error, Warning, Info, Success, and Debug
// critical // Panic, Error
// monitor // Panic, Error, Warning
// verbose // Panic, Error, Warning, Info, Success
// all // Panic, Error, Warning, Info, Success, and Debug
AddWriter(os.Stdout, WithFormatter(FormatWithColours), WithFilter(LabelToType("success")))
// which is equivalent to
// AddWriter(os.Stdout, WithFilter(P | E | W | I | S)) // debug logs are filtered out
func StringToType ¶
StringToType converts a string of codes to a log type/level
Example ¶
AddWriter(os.Stdout, WithFormatter(FormatWithColours), WithFilter(StringToType("PEW")))
// which is equivalent to
// AddWriter(os.Stdout, WithFilter(P | E | W))
func (Type) MarshalJSON ¶
MashalJSON implements json.Marshaller
type WaitOption ¶ added in v2.0.3
type WaitOption func(*waitConfig)
WaitOption configures the behavior of Wait
func WithContext ¶ added in v2.0.3
func WithContext(ctx context.Context) WaitOption
WithContext sets a context for Wait to observe for cancellation
func WithTimeout ¶ added in v2.0.3
func WithTimeout(d time.Duration) WaitOption
WithTimeout sets a maximum duration for Wait to block
type WriterConfig ¶
type WriterConfig struct {
// contains filtered or unexported fields
}
type WriterConfigModifier ¶
type WriterConfigModifier func(c WriterConfig) WriterConfig
func WithFilter ¶
func WithFilter(f Type) WriterConfigModifier
WithFilter creates a WriterConfigModifier that sets a filter on the configuration for a Writer
Example ¶
// None Type = iota // None // P Type = 1 << iota // Panic // E // Error // W // Warning // I // Info // D // Debug // S // Success // Critical = P | E // Panic and Error // Monitor = Critical | W // Panic, Error, and Warning // Verbose = Monitor | I | S // Panic, Error, Warning, Info, and Success // All = Verbose | D // Panic, Error, Warning, Info, Success, and Debug AddWriter(os.Stdout, WithFilter(Monitor)) // which is equivalent to // AddWriter(os.Stdout, WithFilter(P | E | W))
func WithFormatter ¶
func WithFormatter(f Formatter) WriterConfigModifier
WithFormatter creates a WriterConfigModifier that defines how a log message is formatted on the configuration for a Writer. A custom formatter may be provided to convert the Message to any desired format before it is passed to the Writer.