log

package
v0.5.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package log implements adapters between logging types of various used packages

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorTime              = tty.Color256(223)
	ColorContext           = tty.Color256(249)
	ColorStacktrace        = tty.Color256(249)
	ColorName              = tty.Color256(145)
	ColorCaller            = tty.Color256(15)
	ColorLevelUnknown      = tty.Color256(1)
	ColorLevelDebugVerbose = tty.Color256(138)
	ColorLevels            = map[Level]string{
		DebugLevel:  tty.Color256(138),
		InfoLevel:   tty.Color256(12),
		WarnLevel:   tty.Color256(208),
		ErrorLevel:  tty.Color256(124),
		DPanicLevel: tty.Color256(196),
		PanicLevel:  tty.Color256(196),
		FatalLevel:  tty.Color256(196),
	}
)
View Source
var (
	ErrUnsupportedKeyword = errors.New("unsupported keyword")
	ErrBadSyntax          = errors.New("bad syntax")
)
View Source
var (
	MaxLevel   = FatalLevel
	MinLevel   = VerboseLevel(10)
	TraceLevel = MinLevel
)

Functions

func AlwaysFalseFilter

func AlwaysFalseFilter(_ zapcore.Entry) bool

func AlwaysTrueFilter

func AlwaysTrueFilter(_ zapcore.Entry) bool

func ColorLevel

func ColorLevel(l Level) string

func NewGRPCLogger

func NewGRPCLogger(logger *Logger) grpclog.LoggerV2

func NewPionLogger

func NewPionLogger(base *Logger, scope string) logging.LeveledLogger

func NewPionLoggerFactory

func NewPionLoggerFactory(base *Logger) logging.LoggerFactory

func ResetWidths

func ResetWidths()

func UpdateFilter

func UpdateFilter(f *Filter)

Types

type Filter

type Filter struct {
	FilterFunc

	Rules []string // The list of rules used to construct the filter
	Level Level    // The highest level which the filter lets pass-through
}

func CurrentFilter

func CurrentFilter() *Filter

func ParseFilter

func ParseFilter(rules []string) (*Filter, error)

func (*Filter) String

func (f *Filter) String() string

type FilterFunc

type FilterFunc func(zapcore.Entry) bool

FilterFunc is used to check whether to filter the given entry and filters out.

func All

func All(filterFuncs ...FilterFunc) FilterFunc

All checks if all filters return true.

func Any

func Any(filterFuncs ...FilterFunc) FilterFunc

Any checks if any filter returns true.

func ByLevels

func ByLevels(pattern string) (FilterFunc, error)

ByLevels creates a FilterFunc based on a pattern.

Syntax

pattern: LEVELS
LEVELS: LEVEL[,LEVELS]
LEVEL: one of
 -  SEVERITY for matching all levels with equal or higher severity
 - >SEVERITY for matching all levels with equal or higher severity
 - =SEVERITY for matching all levels with equal severity
 - <SEVERITY for matching all levels with lower severity

func ByNamespaces

func ByNamespaces(input string) FilterFunc

ByNamespaces takes a list of patterns to filter out logs based on their namespaces. Patterns are checked using path.Match.

func ParseRule

func ParseRule(rule string) (FilterFunc, error)

ParseRules takes a CLI-friendly set of rules to construct a filter. Syntax

rule: RULE
RULE: one of:
 - LEVELS:NAMESPACES
 - LEVELS
LEVELS: LEVEL[,LEVELS]
LEVEL: see `Level Patterns`
NAMESPACES: NAMESPACE[,NAMESPACES]
NAMESPACE: one of:
 - namespace     // Should be exactly this namespace
 - *mat*ch*      // Should match
 - -NAMESPACE    // Should not match

func ParseRules

func ParseRules(rules []string) (FilterFunc, error)

ParseRules takes a CLI-friendly set of rules to construct a filter.

Syntax

rules: slice of RULE

func Reverse

func Reverse(filterFunc FilterFunc) FilterFunc

Reverse checks is the passed filter returns false.

func (FilterFunc) Level

func (f FilterFunc) Level() zapcore.Level

type Level

type Level zapcore.Level
const (
	DebugLevel Level = iota - 1
	InfoLevel
	WarnLevel
	ErrorLevel
	DPanicLevel
	PanicLevel
	FatalLevel
)

func VerboseLevel

func VerboseLevel(v int) Level

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(text []byte) error

func (Level) Verbosity

func (l Level) Verbosity() int

type Logger

type Logger struct {
	*zap.Logger
}
var (
	Global *Logger
)

func SetupLogging

func SetupLogging(rule *Filter, paths []string, color bool) (logger *Logger, err error)

func (*Logger) DebugV

func (l *Logger) DebugV(verboseLevel int, message string, fields ...zap.Field)

func (*Logger) Level

func (l *Logger) Level() Level

func (*Logger) Named

func (l *Logger) Named(s string) *Logger

func (*Logger) With

func (l *Logger) With(fields ...zap.Field) *Logger

func (*Logger) WithOptions

func (l *Logger) WithOptions(opts ...zap.Option) *Logger

type PionLoggerFactory

type PionLoggerFactory struct {
	// contains filtered or unexported fields
}

PionLoggerFactory is a logger factory backended by zap logger.

func (*PionLoggerFactory) NewLogger

func (f *PionLoggerFactory) NewLogger(scope string) logging.LeveledLogger

NewLogger creates new scoped logger.

func (*PionLoggerFactory) SyncAll

func (f *PionLoggerFactory) SyncAll()

SyncAll calls Sync() method of all child loggers. It is recommended to call this before exiting the program to ensure never loosing buffered log.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL