Documentation
¶
Index ¶
- Constants
- Variables
- func ExtractTime(line []byte) []byte
- func ParseLogTime(line []byte) (t time.Time)
- type ACLFormatter
- type ACLLogFormatter
- type ACLLoggerConfig
- type AccessLogger
- func (l *AccessLogger) Close() error
- func (l *AccessLogger) Config() *Config
- func (l *AccessLogger) Flush()
- func (l *AccessLogger) Log(req *http.Request, res *http.Response)
- func (l *AccessLogger) LogACL(info *acl.IPInfo, blocked bool)
- func (l *AccessLogger) LogError(req *http.Request, err error)
- func (l *AccessLogger) Rotate() (result *RotateResult, err error)
- func (l *AccessLogger) ShouldRotate() bool
- type AnyConfig
- type BackScanner
- type CIDR
- type CombinedFormatter
- type CommonFormatter
- type Config
- type ConfigBase
- type FieldConfig
- func (cfg *FieldConfig) IterCookies(cookies []*http.Cookie) iter.Seq2[string, string]
- func (cfg *FieldConfig) IterHeaders(headers http.Header) iter.Seq2[string, []string]
- func (cfg *FieldConfig) IterQuery(q url.Values) iter.Seq2[string, []string]
- func (cfg *FieldConfig) ZerologCookies(cookies []*http.Cookie) zerolog.LogObjectMarshaler
- func (cfg *FieldConfig) ZerologHeaders(headers http.Header) zerolog.LogObjectMarshaler
- func (cfg *FieldConfig) ZerologQuery(q url.Values) zerolog.LogObjectMarshaler
- type FieldMode
- type Fields
- type File
- type Filterable
- type Filters
- type Format
- type HTTPHeader
- type HTTPMethod
- type Host
- type JSONFormatter
- type LogFilter
- type MockFile
- type MultiWriter
- type MultiWriterInterface
- type ReaderAtSeeker
- type RequestFormatter
- type RequestLoggerConfig
- type Retention
- type RotateResult
- type StatusCodeRange
- type StdoutLogger
- type WriterWithName
Constants ¶
const ( MinBufferSize = 4 * kilobyte MaxBufferSize = 1 * megabyte )
const DefaultBufferSize = 64 * kilobyte // 64KB
const LogTimeFormat = "02/Jan/2006:15:04:05 -0700"
Variables ¶
var ( ErrInvalidSyntax = gperr.New("invalid syntax") ErrZeroValue = gperr.New("zero value") )
var ErrInvalidHTTPHeaderFilter = gperr.New("invalid http header filter")
var ErrInvalidStatusCodeRange = gperr.New("invalid status code range")
Functions ¶
func ExtractTime ¶
ExtractTime extracts the time from the log line. It returns the time if the time is found, otherwise it returns nil.
The returned time is not validated.
func ParseLogTime ¶
ParseLogTime parses the time from the log line. It returns the time if the time is found and valid in the log line, otherwise it returns zero time.
Types ¶
type ACLFormatter ¶
type ACLLoggerConfig ¶
type ACLLoggerConfig struct { ConfigBase LogAllowed bool `json:"log_allowed"` }
func DefaultACLLoggerConfig ¶
func DefaultACLLoggerConfig() *ACLLoggerConfig
func (*ACLLoggerConfig) ToConfig ¶
func (cfg *ACLLoggerConfig) ToConfig() *Config
type AccessLogger ¶
type AccessLogger struct { RequestFormatter ACLFormatter // contains filtered or unexported fields }
func NewAccessLogger ¶
func NewAccessLogger(parent task.Parent, cfg AnyConfig) (*AccessLogger, error)
func NewAccessLoggerWithIO ¶
func NewAccessLoggerWithIO(parent task.Parent, writer WriterWithName, anyCfg AnyConfig) *AccessLogger
func NewMockAccessLogger ¶
func NewMockAccessLogger(parent task.Parent, cfg *RequestLoggerConfig) *AccessLogger
func (*AccessLogger) Close ¶
func (l *AccessLogger) Close() error
func (*AccessLogger) Config ¶
func (l *AccessLogger) Config() *Config
func (*AccessLogger) Flush ¶
func (l *AccessLogger) Flush()
func (*AccessLogger) Rotate ¶
func (l *AccessLogger) Rotate() (result *RotateResult, err error)
func (*AccessLogger) ShouldRotate ¶
func (l *AccessLogger) ShouldRotate() bool
type AnyConfig ¶
type AnyConfig interface { ToConfig() *Config IO() (WriterWithName, error) }
type BackScanner ¶
type BackScanner struct {
// contains filtered or unexported fields
}
BackScanner provides an interface to read a file backward line by line.
func NewBackScanner ¶
func NewBackScanner(file ReaderAtSeeker, chunkSize int) *BackScanner
NewBackScanner creates a new Scanner to read the file backward. chunkSize determines the size of each read chunk from the end of the file.
func (*BackScanner) Bytes ¶
func (s *BackScanner) Bytes() []byte
Bytes returns the most recent line generated by a call to Scan.
func (*BackScanner) Err ¶
func (s *BackScanner) Err() error
Err returns the first non-EOF error encountered by the scanner.
func (*BackScanner) FileSize ¶
func (s *BackScanner) FileSize() int64
FileSize returns the size of the file.
func (*BackScanner) Reset ¶
func (s *BackScanner) Reset() error
func (*BackScanner) Scan ¶
func (s *BackScanner) Scan() bool
Scan advances the scanner to the previous line, which will then be available via the Bytes method. It returns false when there are no more lines.
type CombinedFormatter ¶
type CombinedFormatter struct{ CommonFormatter }
func (*CombinedFormatter) AppendRequestLog ¶
type CommonFormatter ¶
type CommonFormatter struct {
// contains filtered or unexported fields
}
func (*CommonFormatter) AppendRequestLog ¶
type Config ¶
type Config struct { *ConfigBase // contains filtered or unexported fields }
type ConfigBase ¶
type ConfigBase struct { BufferSize int `json:"buffer_size"` Path string `json:"path"` Stdout bool `json:"stdout"` Retention *Retention `json:"retention" aliases:"keep"` }
func (*ConfigBase) IO ¶
func (cfg *ConfigBase) IO() (WriterWithName, error)
func (*ConfigBase) Validate ¶
func (cfg *ConfigBase) Validate() gperr.Error
type FieldConfig ¶
type FieldConfig struct { Default FieldMode `json:"default" validate:"oneof=keep drop redact"` Config map[string]FieldMode `json:"config" validate:"dive,oneof=keep drop redact"` }
func (*FieldConfig) IterCookies ¶
func (*FieldConfig) IterHeaders ¶
func (*FieldConfig) ZerologCookies ¶
func (cfg *FieldConfig) ZerologCookies(cookies []*http.Cookie) zerolog.LogObjectMarshaler
func (*FieldConfig) ZerologHeaders ¶
func (cfg *FieldConfig) ZerologHeaders(headers http.Header) zerolog.LogObjectMarshaler
func (*FieldConfig) ZerologQuery ¶
func (cfg *FieldConfig) ZerologQuery(q url.Values) zerolog.LogObjectMarshaler
type Fields ¶
type Fields struct { Headers FieldConfig `json:"headers"` Query FieldConfig `json:"query"` Cookies FieldConfig `json:"cookies"` }
type Filterable ¶
type Format ¶
type Format string
var ( FormatCommon Format = "common" FormatCombined Format = "combined" FormatJSON Format = "json" ReqLoggerFormats = []Format{FormatCommon, FormatCombined, FormatJSON} )
type HTTPMethod ¶
type HTTPMethod string
type JSONFormatter ¶
type JSONFormatter struct{ CommonFormatter }
func (*JSONFormatter) AppendRequestLog ¶
type MockFile ¶
func NewMockFile ¶
func NewMockFile() *MockFile
type MultiWriter ¶
type MultiWriter struct {
// contains filtered or unexported fields
}
func (*MultiWriter) Name ¶
func (w *MultiWriter) Name() string
func (*MultiWriter) Unwrap ¶
func (w *MultiWriter) Unwrap() []io.Writer
type MultiWriterInterface ¶
type RequestFormatter ¶
type RequestLoggerConfig ¶
type RequestLoggerConfig struct { ConfigBase Format Format `json:"format" validate:"oneof=common combined json"` Filters Filters `json:"filters"` Fields Fields `json:"fields"` }
func DefaultRequestLoggerConfig ¶
func DefaultRequestLoggerConfig() *RequestLoggerConfig
func (*RequestLoggerConfig) ToConfig ¶
func (cfg *RequestLoggerConfig) ToConfig() *Config
type Retention ¶
type Retention struct { Days uint64 `json:"days"` Last uint64 `json:"last"` KeepSize uint64 `json:"keep_size"` }
type RotateResult ¶
type RotateResult struct { Filename string OriginalSize int64 // original size of the file NumBytesRead int64 // number of bytes read from the file NumBytesKeep int64 // number of bytes to keep NumLinesRead int // number of lines read from the file NumLinesKeep int // number of lines to keep NumLinesInvalid int // number of invalid lines }
func (*RotateResult) Add ¶
func (r *RotateResult) Add(other *RotateResult)
func (*RotateResult) Print ¶
func (r *RotateResult) Print(logger *zerolog.Logger)
type StatusCodeRange ¶
func (*StatusCodeRange) Includes ¶
func (r *StatusCodeRange) Includes(code int) bool
func (*StatusCodeRange) Parse ¶
func (r *StatusCodeRange) Parse(v string) error
Parse implements strutils.Parser.
func (*StatusCodeRange) String ¶
func (r *StatusCodeRange) String() string
type StdoutLogger ¶
func (*StdoutLogger) Name ¶
func (l *StdoutLogger) Name() string
type WriterWithName ¶
func NewMultiWriter ¶
func NewMultiWriter(writers ...WriterWithName) WriterWithName