Documentation
¶
Overview ¶
Package logging provides structured application logging, request-scoped log aggregation, and HTTP/Gin access log middleware.
Index ¶
- func IntoContext(ctx context.Context, logger *Logger) context.Context
- func SetDefaultLogger(logger *Logger)
- type AccessLogEntry
- type Config
- type Field
- func AnyField(key string, value interface{}) Field
- func BoolField(key string, value bool) Field
- func DurationField(key string, value time.Duration) Field
- func ErrorField(err error) Field
- func Int64Field(key string, value int64) Field
- func IntField(key string, value int) Field
- func StringField(key, value string) Field
- func StringSliceField(key string, value []string) Field
- func TimeField(key string, value time.Time) Field
- type Format
- type Level
- type Logger
- func (l *Logger) AppendRequestLogError(err error)
- func (l *Logger) AppendRequestLogField(key string, value interface{})
- func (l *Logger) AppendRequestLogFields(fields ...Field)
- func (l *Logger) AppendRequestLogMessage(message string)
- func (l *Logger) Debug(message string, fields ...Field)
- func (l *Logger) Error(message string, fields ...Field)
- func (l *Logger) Fatal(message string, fields ...Field)
- func (l *Logger) Info(message string, fields ...Field)
- func (l *Logger) OverrideRequestLogLevel(level Level)
- func (l *Logger) Sync() error
- func (l *Logger) Warn(message string, fields ...Field)
- func (l *Logger) WithComponent(component string) *Logger
- func (l *Logger) WithFields(fields ...Field) *Logger
- func (l *Logger) WithName(name string) *Logger
- func (l *Logger) WithRequestLogAccumulator(accumulator *RequestLogAccumulator) *Logger
- func (l *Logger) WriteAccessLog(entry AccessLogEntry)
- type Observer
- type Redactor
- type RequestLogAccumulator
- type RequestLogLimits
- type SamplingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntoContext ¶
IntoContext stores logger into ctx.
func SetDefaultLogger ¶
func SetDefaultLogger(logger *Logger)
SetDefaultLogger sets the process default logger.
Types ¶
type AccessLogEntry ¶
type AccessLogEntry struct {
LogType string
Timestamp time.Time
Level Level
Service string
Env string
Version string
Hostname string
RequestID string
TraceID string
SpanID string
Method string
Path string
Route string
StatusCode int
Latency time.Duration
LatencyMS int64
ClientIP string
UserAgent string
Referer string
RequestBytes int64
ResponseBytes int64
RequestFields map[string]interface{}
RequestMessages []string
RequestErrors []string
RequestLogTruncated bool
PanicRecovered bool
}
AccessLogEntry is the final structured request log payload.
type Config ¶
type Config struct {
Service string
Env string
Version string
Hostname string
Level Level
Format Format
TimeZone *time.Location
AddCaller bool
AppWriter io.Writer
AccessWriter io.Writer
ErrorWriter io.Writer
StaticFields []Field
Redactor Redactor
Observer Observer
Sampling SamplingConfig
}
Config controls logger construction.
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is the public structured field representation.
func DurationField ¶
DurationField builds a duration field.
func ErrorField ¶
ErrorField builds an error field under the standard error key.
func StringSliceField ¶
StringSliceField builds a string slice field.
type Format ¶
type Format uint8
Format is the log output format.
func ParseFormat ¶
ParseFormat parses a string format.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the public structured logger.
func FromContext ¶
FromContext returns logger from ctx or the default logger.
func MustFromContext ¶
MustFromContext returns logger from ctx and panics when absent.
func MustNewLogger ¶
MustNewLogger constructs a new logger or panics.
func (*Logger) AppendRequestLogError ¶
AppendRequestLogError appends an error to the current request log.
func (*Logger) AppendRequestLogField ¶
AppendRequestLogField appends a request field to the current request log.
func (*Logger) AppendRequestLogFields ¶
AppendRequestLogFields appends request fields to the current request log.
func (*Logger) AppendRequestLogMessage ¶
AppendRequestLogMessage appends a message to the current request log.
func (*Logger) OverrideRequestLogLevel ¶
OverrideRequestLogLevel overrides the current request access log level.
func (*Logger) WithComponent ¶
WithComponent returns a derived logger with a component field.
func (*Logger) WithFields ¶
WithFields returns a derived logger with extra structured fields.
func (*Logger) WithRequestLogAccumulator ¶
func (l *Logger) WithRequestLogAccumulator(accumulator *RequestLogAccumulator) *Logger
WithRequestLogAccumulator returns a derived request-scoped logger.
func (*Logger) WriteAccessLog ¶
func (l *Logger) WriteAccessLog(entry AccessLogEntry)
WriteAccessLog emits the final structured access log entry.
type Observer ¶
type Observer interface {
ObserveAppLog(level Level, logType string)
ObserveAccessLog(level Level, statusCode int, route string, latency time.Duration)
}
Observer receives structured log emission callbacks.
type Redactor ¶
type Redactor interface {
RedactField(key string, value interface{}) interface{}
}
Redactor redacts sensitive field values before output.
func DefaultRedactor ¶
func DefaultRedactor() Redactor
DefaultRedactor returns the built-in redactor.
type RequestLogAccumulator ¶
type RequestLogAccumulator struct {
// contains filtered or unexported fields
}
RequestLogAccumulator aggregates per-request structured additions.
func NewRequestLogAccumulator ¶
func NewRequestLogAccumulator(limits RequestLogLimits) *RequestLogAccumulator
NewRequestLogAccumulator returns a new request log accumulator.
type RequestLogLimits ¶
RequestLogLimits bounds request aggregation growth.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
gindemo
command
|
|
|
nethttpdemo
command
|
|
|
Package logginggin provides Gin access log middleware built on top of the logging package.
|
Package logginggin provides Gin access log middleware built on top of the logging package. |
|
Package logginghttp provides net/http access log middleware built on top of the logging package.
|
Package logginghttp provides net/http access log middleware built on top of the logging package. |
|
internal
|
|