Documentation ¶
Index ¶
- Constants
- Variables
- func FileWriter(name string) (wc io.WriteCloser)
- func NewStackError(msg string) error
- func NewStackErrorf(fmt string, args ...any) error
- func Print(v ...any)
- func PrintC(ctx context.Context, v ...any)
- func Printf(format string, v ...any)
- func PrintfC(ctx context.Context, format string, v ...any)
- func RegisterCollector(c Collector)
- func RemoveCollector(c Collector)
- func SetDefaultOutput(w ...io.Writer)
- func SetLoggerLevel(level Level)
- func Tail(opts TailOptions, out io.Writer) error
- func TailContext(ctx context.Context, opts TailOptions, out io.Writer) error
- func TailHistory(ctx context.Context, opts *TailOptions, out io.Writer) error
- func ToSlog(logger *Logger) *slog.Logger
- func WrapStackError(err error) error
- type Collector
- type Context
- type DefaultWriter
- type Domain
- type DomainFilter
- type Event
- func Debug() *Event
- func DebugC(ctx context.Context) *Event
- func Err(err error) *Event
- func ErrC(ctx context.Context, err error) *Event
- func ErrStack(err any) *Event
- func ErrStackC(ctx context.Context, err any) *Event
- func Error() *Event
- func ErrorC(ctx context.Context) *Event
- func Fatal() *Event
- func FatalC(ctx context.Context) *Event
- func Info() *Event
- func InfoC(ctx context.Context) *Event
- func Log() *Event
- func LogC(ctx context.Context) *Event
- func Panic() *Event
- func PanicC(ctx context.Context) *Event
- func Trace() *Event
- func TraceC(ctx context.Context) *Event
- func Warn() *Event
- func WarnC(ctx context.Context) *Event
- func WithLevel(level Level) *Event
- func WithLevelC(ctx context.Context, level Level) *Event
- type EventEnhancer
- type FileInfo
- type FileKind
- type Filter
- type Hook
- type Level
- type LevelFilter
- type LevelWriter
- type Line
- type Logger
- type MultiFilter
- type MuxWriter
- type Parser
- func (r *Parser) Close() error
- func (r *Parser) Filters() []Filter
- func (r *Parser) Flags() StreamFlag
- func (r *Parser) IsTail() bool
- func (r *Parser) Next() (v Line, err error)
- func (r *Parser) NextContext(ctx context.Context) (v Line, err error)
- func (r *Parser) WithFilter(f ...Filter) *Parser
- func (r *Parser) WithQuota(q *ParserQuota) *Parser
- type ParserQuota
- type Sampler
- type SearchFilter
- type StreamFlag
- type TailOptions
- type TextAdapter
- type TimeFilter
Constants ¶
const ( LevelDebug = zerolog.DebugLevel LevelInfo = zerolog.InfoLevel LevelWarn = zerolog.WarnLevel LevelError = zerolog.ErrorLevel LevelFatal = zerolog.FatalLevel LevelPanic = zerolog.PanicLevel LevelNone = zerolog.NoLevel LevelSuppress = zerolog.Disabled LevelTrace = zerolog.TraceLevel )
const ( LogRetentionDays = 28 LogMaxSizeMB = 16 LogCompress = false )
const (
DomainFieldName = "dom"
)
XLog uses the caller field in zerolog to record what we call "domains" which are lazily registrable pub/sub queue paths that uniquely identify what it is that the logger is currently logging about. E.g. pmesh myfrontend myfrontend.pid
Variables ¶
var ErrQuotaExceeded = errors.New("quota exceeded")
Functions ¶
func FileWriter ¶
func FileWriter(name string) (wc io.WriteCloser)
func NewStackError ¶
func NewStackErrorf ¶ added in v0.2.2
func Print ¶
func Print(v ...any)
Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.
func Printf ¶
Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.
func RegisterCollector ¶
func RegisterCollector(c Collector)
func RemoveCollector ¶
func RemoveCollector(c Collector)
func TailContext ¶
func TailHistory ¶
func WrapStackError ¶
Types ¶
type DefaultWriter ¶
type DefaultWriter struct{}
type Domain ¶
type Domain struct {
// contains filtered or unexported fields
}
Domain represents a domain.
func ContextDomain ¶
ContextDomain returns the domain from the context.
type DomainFilter ¶
type DomainFilter string
DomainFilter filters logs by domain
func (DomainFilter) Test ¶
func (d DomainFilter) Test(line Line, flags StreamFlag) (bool, bool)
func (DomainFilter) TestFile ¶
func (d DomainFilter) TestFile(fi *FileInfo) bool
func (DomainFilter) TestRaw ¶
func (d DomainFilter) TestRaw(line string) bool
type Event ¶
func Debug ¶
func Debug() *Event
Debug starts a new message with debug level.
You must call Msg on the returned event in order to send the event.
func Err ¶
Err starts a new message with error level with err as a field if not nil or with info level if err is nil.
You must call Msg on the returned event in order to send the event.
func ErrStack ¶
ErrStack starts a new message with error level with err as a field if not nil or with info level if err is nil. The stack trace is attached to the event.
You must call Msg on the returned event in order to send the event.
func Error ¶
func Error() *Event
Error starts a new message with error level.
You must call Msg on the returned event in order to send the event.
func Fatal ¶
func Fatal() *Event
Fatal starts a new message with fatal level. The os.Exit(1) function is called by the Msg method.
You must call Msg on the returned event in order to send the event.
func Info ¶
func Info() *Event
Info starts a new message with info level.
You must call Msg on the returned event in order to send the event.
func Log ¶
func Log() *Event
Log starts a new message with no level. Setting GlobalLevel to Disabled will still disable events produced by this method.
You must call Msg on the returned event in order to send the event.
func Panic ¶
func Panic() *Event
Panic starts a new message with panic level. The message is also sent to the panic function.
You must call Msg on the returned event in order to send the event.
func Trace ¶
func Trace() *Event
Trace starts a new message with trace level.
You must call Msg on the returned event in order to send the event.
func Warn ¶
func Warn() *Event
Warn starts a new message with warn level.
You must call Msg on the returned event in order to send the event.
type EventEnhancer ¶
type EventEnhancer interface {
MarshalZerologObject(e *Event)
}
func EnhanceRequest ¶
func EnhanceRequest(r *http.Request) EventEnhancer
type FileInfo ¶
type Filter ¶
type Filter interface { // TestRaw tests a raw log line for being a candidate for parsing // This is used to skip parsing lines that are known to be irrelevant TestRaw(string) (include bool) // Test tests a parsed log line for inclusion Test(line Line, flags StreamFlag) (include bool, stop bool) // Tests file info for inclusion TestFile(*FileInfo) (include bool) }
type LevelFilter ¶
type LevelFilter Level
LevelFilter filters logs by minimum level
func (LevelFilter) Test ¶
func (f LevelFilter) Test(line Line, flags StreamFlag) (bool, bool)
func (LevelFilter) TestFile ¶
func (f LevelFilter) TestFile(*FileInfo) bool
func (LevelFilter) TestRaw ¶
func (f LevelFilter) TestRaw(line string) bool
type LevelWriter ¶
type LevelWriter = zerolog.LevelWriter
func NewConsoleWriter ¶
func NewConsoleWriter(f io.Writer) LevelWriter
func StderrWriter ¶
func StderrWriter() LevelWriter
func StdoutWriter ¶
func StdoutWriter() LevelWriter
type Logger ¶
func Ctx ¶
Ctx returns the Logger associated with the ctx. If no logger is associated, a disabled logger is returned.
type MultiFilter ¶
type MultiFilter []Filter
MultiFilter is a collection of filters
func (MultiFilter) Append ¶
func (f MultiFilter) Append(list ...Filter) MultiFilter
func (MultiFilter) As ¶
func (f MultiFilter) As(out any) bool
func (MultiFilter) Test ¶
func (f MultiFilter) Test(line Line, flags StreamFlag) (bool, bool)
func (MultiFilter) TestFile ¶
func (f MultiFilter) TestFile(fi *FileInfo) bool
func (MultiFilter) TestRaw ¶
func (f MultiFilter) TestRaw(line string) bool
type MuxWriter ¶
type MuxWriter struct {
// contains filtered or unexported fields
}
Mux writer is a writer that buffers lines and writes them in order of their timestamps. It is used to write logs from multiple sources to a single output, while preserving the order of the logs. Additionally, it inserts sending host information into the caller data.
func ToMuxWriter ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func NewFileParser ¶
func NewFileParser(path string, fl StreamFlag) (*Parser, error)
NewFileParser creates a new parser for the file at path. The file is opened in read-only mode. If the file is a gzip file, it is automatically decompressed. In which case, the returned parser will always be a head parser.
func NewParser ¶
func NewParser(r io.ReadCloser, fl StreamFlag) (p *Parser, err error)
func (*Parser) Flags ¶
func (r *Parser) Flags() StreamFlag
func (*Parser) WithFilter ¶
func (*Parser) WithQuota ¶
func (r *Parser) WithQuota(q *ParserQuota) *Parser
type ParserQuota ¶
func NewParserQuota ¶
func NewParserQuota(maxIo, maxLines int64) (q *ParserQuota)
func (*ParserQuota) ConsumeIo ¶
func (r *ParserQuota) ConsumeIo(n int) bool
func (*ParserQuota) ConsumeLine ¶
func (r *ParserQuota) ConsumeLine() bool
type SearchFilter ¶
type SearchFilter string
SearchFilter filters logs by substring
func (SearchFilter) Test ¶
func (f SearchFilter) Test(line Line, flags StreamFlag) (bool, bool)
func (SearchFilter) TestFile ¶
func (f SearchFilter) TestFile(*FileInfo) bool
func (SearchFilter) TestRaw ¶
func (f SearchFilter) TestRaw(line string) bool
type StreamFlag ¶
type StreamFlag int
const ( StreamTail StreamFlag = 1 << 0 StreamHead StreamFlag = 1 << 1 StreamGzip StreamFlag = 1 << 2 StreamBufferOk StreamFlag = 1 << 3 // Buffer is ok to use if we can't seek )
type TailOptions ¶
type TailOptions struct { Domain string `json:"domain,omitempty"` // Domain to filter logs in MinLevel Level `json:"level,omitempty"` // Level filter After time.Time `json:"after,omitempty"` // Time filter Before time.Time `json:"before,omitempty"` // Time filter Search string `json:"substr,omitempty"` // Substring filter LineLimit int64 `json:"line_limit,omitempty"` // Max lines to emit from history IoLimit int64 `json:"io_limit,omitempty"` // Max bytes to read in history Follow bool `json:"follow,omitempty"` // Follow logs in real time Hostname string `json:"hostname,omitempty"` // Hostname to filter logs in (in public format). Not used in local implementation Viral bool `json:"viral,omitempty"` // Viral logs, will spread to all nodes. Not used in local implementation }
func (TailOptions) Filter ¶
func (o TailOptions) Filter() Filter
func (TailOptions) WithRay ¶
func (o TailOptions) WithRay(rayStr string) (opts TailOptions, err error)
type TextAdapter ¶
type TextAdapter struct {
// contains filtered or unexported fields
}
func ToTextWriter ¶
func ToTextWriter(logger *Logger, level Level) (w io.Writer, te *TextAdapter)
Creates a new writer that writes valid JSON objects to the logger.
func (*TextAdapter) Flush ¶
func (w *TextAdapter) Flush() error
func (*TextAdapter) WriteLevel ¶
func (w *TextAdapter) WriteLevel(lv Level, p []byte) (n int, err error)
type TimeFilter ¶
TimeFilter filters logs by time
func (TimeFilter) Test ¶
func (f TimeFilter) Test(line Line, flags StreamFlag) (ok bool, stop bool)
func (TimeFilter) TestFile ¶
func (f TimeFilter) TestFile(fi *FileInfo) bool
func (TimeFilter) TestRaw ¶
func (f TimeFilter) TestRaw(line string) bool