Documentation
¶
Overview ¶
Package blip provides a simple and efficient logging library. It is designed to be easy to use and flexible, allowing to customize the logging output format, level, and other settings. It supports JSON and console output formats and provides an inteface for custom encoders.
Index ¶
- Variables
- func ContextWithFields(ctx context.Context, fields F) context.Context
- type Buffer
- func (buf *Buffer) Write(b []byte) (int, error)
- func (buf *Buffer) WriteBase64(b64enc *base64.Encoding, data []byte)
- func (buf *Buffer) WriteBool(b bool)
- func (buf *Buffer) WriteBytes(b ...byte)
- func (buf *Buffer) WriteDuration(d time.Duration)
- func (buf *Buffer) WriteEscapedString(str string)
- func (buf *Buffer) WriteFloat(f float64, bitSize int)
- func (buf *Buffer) WriteInt(i int64)
- func (buf *Buffer) WriteRune(r rune)
- func (buf *Buffer) WriteString(str string)
- func (buf *Buffer) WriteTime(t time.Time, format string)
- func (buf *Buffer) WriteUint(i uint64)
- type Config
- type ConsoleEncoder
- func (e *ConsoleEncoder) EncodeFields(buf *Buffer, lev Level, fields *[]Field)
- func (e *ConsoleEncoder) EncodeLevel(buf *Buffer, lev Level)
- func (e *ConsoleEncoder) EncodeMessage(buf *Buffer, msg string)
- func (e *ConsoleEncoder) EncodeStackTrace(buf *Buffer, skip int)
- func (e *ConsoleEncoder) EncodeTime(buf *Buffer)
- func (e *ConsoleEncoder) End(buf *Buffer)
- func (e *ConsoleEncoder) Start(_ *Buffer)
- type Encoder
- type F
- type Field
- type JSONEncoder
- func (e *JSONEncoder) EncodeFields(buf *Buffer, _ Level, fields *[]Field)
- func (e *JSONEncoder) EncodeLevel(buf *Buffer, lev Level)
- func (e *JSONEncoder) EncodeMessage(buf *Buffer, msg string)
- func (e *JSONEncoder) EncodeStackTrace(buf *Buffer, skip int)
- func (e *JSONEncoder) EncodeTime(buf *Buffer)
- func (e *JSONEncoder) End(buf *Buffer)
- func (e *JSONEncoder) Start(buf *Buffer)
- type Level
- type Logger
- func (l *Logger) Debug(ctx context.Context, msg string, fields ...F)
- func (l *Logger) Error(ctx context.Context, msg string, fields ...F)
- func (l *Logger) Fatal(ctx context.Context, msg string, fields ...F)
- func (l *Logger) Info(ctx context.Context, msg string, fields ...F)
- func (l *Logger) Panic(ctx context.Context, msg string, fields ...F)
- func (l *Logger) Trace(ctx context.Context, msg string, fields ...F)
- func (l *Logger) Warn(ctx context.Context, msg string, fields ...F)
Constants ¶
This section is empty.
Variables ¶
var ( // DurationFieldPrecision controls how duration values are truncated when // logged. DurationFieldPrecision = time.Millisecond // TimeFieldFormat controls the format used for time field values. Log entry // timestamps are configured with the TimeFieldFormat field in the Config // struct. TimeFieldFormat = time.RFC3339 )
Functions ¶
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a byte buffer used for encoding log entries. WARNING: Buffer should not be initialized manually. It is pooled to reduce allocations.
func (*Buffer) WriteBase64 ¶
WriteBase64 writes a byte slice to the buffer as a base64-encoded string.
func (*Buffer) WriteBytes ¶
WriteBytes writes a byte slice to the buffer.
func (*Buffer) WriteDuration ¶
WriteDuration writes a time.Duration value to the buffer.
func (*Buffer) WriteEscapedString ¶
WriteEscapedString writes a string to the buffer, escaping special characters as needed. It handles both ASCII and Unicode characters. The string is enclosed in double quotes.
func (*Buffer) WriteFloat ¶
WriteFloat writes a float64 value to the buffer with the specified bit size.
func (*Buffer) WriteString ¶
WriteString writes a string to the buffer.
type Config ¶
type Config struct {
Level Level
Output io.Writer
Encoder Encoder
StackTraceLevel Level
StackTraceSkip int
}
Config is the configuration structure for the logger.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a default configuration for the logger.
type ConsoleEncoder ¶
type ConsoleEncoder struct {
TimeFormat string
TimePrecision time.Duration
MinMessageWidth int
SortFields bool
Color bool
// contains filtered or unexported fields
}
ConsoleEncoder is a console encoder that formats log messages in a human-readable format.
func NewConsoleEncoder ¶
func NewConsoleEncoder() *ConsoleEncoder
NewConsoleEncoder creates a new console encoder with the given configuration. The encoder formats log messages in a human-readable format, with colorized levels and optional field sorting. The encoder also supports a minimum message width for padding.
func (*ConsoleEncoder) EncodeFields ¶
func (e *ConsoleEncoder) EncodeFields(buf *Buffer, lev Level, fields *[]Field)
EncodeFields encodes the fields of the log message.
func (*ConsoleEncoder) EncodeLevel ¶
func (e *ConsoleEncoder) EncodeLevel(buf *Buffer, lev Level)
EncodeLevel encodes the log level of the message.
func (*ConsoleEncoder) EncodeMessage ¶
func (e *ConsoleEncoder) EncodeMessage(buf *Buffer, msg string)
EncodeMessage encodes the log message.
func (*ConsoleEncoder) EncodeStackTrace ¶
func (e *ConsoleEncoder) EncodeStackTrace(buf *Buffer, skip int)
EncodeStackTrace encodes the stack trace of the log message.
func (*ConsoleEncoder) EncodeTime ¶
func (e *ConsoleEncoder) EncodeTime(buf *Buffer)
EncodeTime encodes the time of the log message.
func (*ConsoleEncoder) End ¶
func (e *ConsoleEncoder) End(buf *Buffer)
End writes the end of the log message.
func (*ConsoleEncoder) Start ¶
func (e *ConsoleEncoder) Start(_ *Buffer)
Start writes the beginning of the log message.
type Encoder ¶
type Encoder interface {
// Start writes the beginning of the log message.
Start(buf *Buffer)
// EncodeTime encodes the time of the log message.
EncodeTime(buf *Buffer)
// EncodeLevel encodes the log level of the message.
EncodeLevel(buf *Buffer, lev Level)
// EncodeMessage encodes the log message.
EncodeMessage(buf *Buffer, msg string)
// EncodeFields encodes the fields of the log message.
EncodeFields(buf *Buffer, lev Level, fields *[]Field)
// EncodeStackTrace encodes the stack trace of the log message.
EncodeStackTrace(buf *Buffer, skip int)
// End writes the end of the log message.
End(buf *Buffer)
}
Encoder is an interface for encoding log messages.
type F ¶
F is a convenient alias for a map of fields.
func FieldsFromContext ¶
FieldsFromContext retrieves fields from the context. If no fields are found, it returns nil.
type JSONEncoder ¶
type JSONEncoder struct {
TimeFormat string
TimePrecision time.Duration
Base64Encoding *base64.Encoding
KeyTime string
KeyLevel string
KeyMessage string
KeyStackTrace string
// contains filtered or unexported fields
}
JSONEncoder is an encoder that encodes log messages in JSON format.
func NewJSONEncoder ¶
func NewJSONEncoder() *JSONEncoder
NewJSONEncoder creates a new JSON encoder with the given configuration. The encoder formats log messages in JSON format, with optional and fields.
func (*JSONEncoder) EncodeFields ¶
func (e *JSONEncoder) EncodeFields(buf *Buffer, _ Level, fields *[]Field)
EncodeFields encodes the fields of the log message.
func (*JSONEncoder) EncodeLevel ¶
func (e *JSONEncoder) EncodeLevel(buf *Buffer, lev Level)
EncodeLevel encodes the log level of the message.
func (*JSONEncoder) EncodeMessage ¶
func (e *JSONEncoder) EncodeMessage(buf *Buffer, msg string)
EncodeMessage encodes the log message.
func (*JSONEncoder) EncodeStackTrace ¶
func (e *JSONEncoder) EncodeStackTrace(buf *Buffer, skip int)
EncodeStackTrace encodes the stack trace of the log message.
func (*JSONEncoder) EncodeTime ¶
func (e *JSONEncoder) EncodeTime(buf *Buffer)
EncodeTime encodes the time of the log message.
func (*JSONEncoder) End ¶
func (e *JSONEncoder) End(buf *Buffer)
End writes the end of the log message.
func (*JSONEncoder) Start ¶
func (e *JSONEncoder) Start(buf *Buffer)
Start writes the beginning of the log message.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a the main structure used to log messages.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
demo
command
Package main is a demo application for the blip logger.
|
Package main is a demo application for the blip logger. |
|
pprof
command
Package main enables CPU profiling and logs 10M entries.
|
Package main enables CPU profiling and logs 10M entries. |
|
ctx
|
|
|
log
Package log provides a shim for the blip logger, allowing to use it with context.
|
Package log provides a shim for the blip logger, allowing to use it with context. |
|
noctx
|
|
|
log
Package log provides a shim for the blip logger, allowing to use it without context.
|
Package log provides a shim for the blip logger, allowing to use it without context. |