Documentation ¶
Index ¶
- Variables
- func Configure(config Config) error
- func KvParse(line string) map[string]string
- func KvParseAll(l string) []map[string]string
- type Config
- type Factory
- type Field
- type KvConfig
- type KvLogger
- func (l *KvLogger) Bytes() []byte
- func (l *KvLogger) Err(err error) Logger
- func (l *KvLogger) Error(ctx string) Logger
- func (l *KvLogger) Fatal(ctx string) Logger
- func (l *KvLogger) Field(field Field) Logger
- func (l *KvLogger) Fixed()
- func (l *KvLogger) Info(ctx string) Logger
- func (l *KvLogger) Int(key string, value int) Logger
- func (l *KvLogger) Int64(key string, value int64) Logger
- func (l *KvLogger) Log()
- func (l *KvLogger) LogTo(out io.Writer)
- func (l *KvLogger) MultiUse() Logger
- func (l *KvLogger) Release()
- func (l *KvLogger) Reset()
- func (l *KvLogger) String(key string, value string) Logger
- func (l *KvLogger) Warn(ctx string) Logger
- type Level
- type Logger
- type Noop
- func (_ Noop) Bytes() []byte
- func (n Noop) Err(err error) Logger
- func (n Noop) Error(ctx string) Logger
- func (n Noop) Fatal(ctx string) Logger
- func (n Noop) Field(field Field) Logger
- func (n Noop) Fixed()
- func (n Noop) Info(ctx string) Logger
- func (n Noop) Int(key string, value int) Logger
- func (n Noop) Int64(key string, value int64) Logger
- func (_ Noop) Log()
- func (_ Noop) LogTo(io.Writer)
- func (n Noop) MultiUse() Logger
- func (_ Noop) Release()
- func (_ Noop) Reset()
- func (n Noop) String(key string, value string) Logger
- func (n Noop) Warn(ctx string) Logger
- type Pool
- type StructuredError
Constants ¶
This section is empty.
Variables ¶
var (
Out io.Writer = os.Stderr
)
Functions ¶
func KvParseAll ¶
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
type KvLogger ¶
type KvLogger struct {
// contains filtered or unexported fields
}
func NewKvLogger ¶
func (*KvLogger) Bytes ¶
Get the bytes from the logger. This is only valid before Log is called (after log is called, you'll get an empty slice). Only really useful for testing.
func (*KvLogger) Error ¶
Log an error-level message. Every message must have a [hopefully] unique context
func (*KvLogger) Fatal ¶
Log an fatal-level message. Every message must have a [hopefully] unique context
func (*KvLogger) Fixed ¶
func (l *KvLogger) Fixed()
Logger will _always_ include this data. Meant to be used with the Field builder. Even once released to the pool and re-checked out, this data will still be in the logger. For checkout-specific data, see MultiUse().
func (*KvLogger) Info ¶
Log an info-level message. Every message must have a [hopefully] unique context
type Logger ¶
type Logger interface { // Actually log the data to the configured output // If the logger was not configured for MultiUse, this // must release the logger back to the pool (if any). Log() // Log to the specific writer LogTo(io.Writer) // Resets the logger, without releasing it back to the pool. // Reset must not erased any fixed data Reset() // Releases the logger back to the pool, if one is configured. Release() // Gets the log data Bytes() []byte // Set the level and context for a new log entry Info(ctx string) Logger Warn(ctx string) Logger Error(ctx string) Logger Fatal(ctx string) Logger // Log an error Err(err error) Logger // Any data already in the logger will be including in _every_ // message ever generated from this logger. This data survives both // a reset and a release. // As an example of where this could be used is a project owned loggers // in which case these loggers could have the project_id always included // in any log entry. Fixed() // Any data already in the logger will be including in _every_ // message generated until the logger is released. This data survives a // a reset but not a release. // This is meant to be used for a request-owned logger where every entry // logged with the logger has request_id. MultiUse() Logger // Add an int value to the current entry Int(key string, value int) Logger // Add an int64 value to the current entry Int64(key string, value int64) Logger // Add an string value to the current entry String(key string, value string) Logger // Log a field Field(field Field) Logger }
type StructuredError ¶
type StructuredError struct { Code int `json:"code"` Err error `json:"err"` Data map[string]any `json:"data"` }
An error that's designed to be logged in a more structured manner
func Err ¶
func Err(code int, err error) *StructuredError
func (StructuredError) Error ¶
func (e StructuredError) Error() string
func (*StructuredError) Int ¶
func (e *StructuredError) Int(key string, value int) *StructuredError
func (*StructuredError) String ¶
func (e *StructuredError) String(key string, value string) *StructuredError