log

package
v0.0.0-...-92b010d Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLevel = zerolog.DebugLevel
	InfoLevel  = zerolog.InfoLevel
	WarnLevel  = zerolog.WarnLevel
	ErrorLevel = zerolog.ErrorLevel
	FatalLevel = zerolog.FatalLevel
	Disabled   = zerolog.Disabled
)

const

Variables

This section is empty.

Functions

func Close

func Close()

Close flushes all log writer

func ConsoleWriter

func ConsoleWriter(consoleConf ...ConsoleConf) io.Writer

ConsoleWriter gens console with conf provided.

func RedisWriter

func RedisWriter(redisConf ...RedisConfig) io.Writer

RedisWriter generate redis writer.

func SetAttachment

func SetAttachment(kv map[string]string)

SetAttachment add global kv to logger

func SetCallDepth

func SetCallDepth(n int)

SetCallDepth set call depth for show line number.

func SetEnableAsync

func SetEnableAsync()

SetEnableAsync enables async log, should use Close func to wait all flushed.

func SetLevel

func SetLevel(l Level)

SetLevel set global log max level.

func SetOutput

func SetOutput(w ...io.Writer)

SetOutput set multi log writer, careful, all SetXXX method are non-thread safe.

func TakeStacktrace

func TakeStacktrace(optionalSkip ...int) string

TakeStacktrace is helper func to take snap short of stack trace.

Types

type BasicSampler

type BasicSampler = zerolog.BasicSampler

BasicSampler is a sampler that will send every Nth events, regardless of there level.

type Buffer

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

Buffer is a thin wrapper around a byte slice. It's intended to be pooled, so the only way to construct one is via a Pool.

func (*Buffer) AppendBool

func (b *Buffer) AppendBool(v bool)

AppendBool appends a bool to the underlying buffer.

func (*Buffer) AppendByte

func (b *Buffer) AppendByte(v byte)

AppendByte writes a single byte to the Buffer.

func (*Buffer) AppendFloat

func (b *Buffer) AppendFloat(f float64, bitSize int)

AppendFloat appends a float to the underlying buffer. It doesn't quote NaN or +/- Inf.

func (*Buffer) AppendInt

func (b *Buffer) AppendInt(i int64)

AppendInt appends an integer to the underlying buffer (assuming base 10).

func (*Buffer) AppendString

func (b *Buffer) AppendString(s string)

AppendString writes a string to the Buffer.

func (*Buffer) AppendUint

func (b *Buffer) AppendUint(i uint64)

AppendUint appends an unsigned integer to the underlying buffer (assuming base 10).

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns a mutable reference to the underlying byte slice.

func (*Buffer) Cap

func (b *Buffer) Cap() int

Cap returns the capacity of the underlying byte slice.

func (*Buffer) Free

func (b *Buffer) Free()

Free returns the Buffer to its Pool.

Callers must not retain references to the Buffer after calling Free.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the length of the underlying byte slice.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the underlying byte slice. Subsequent writes re-use the slice's backing array.

func (*Buffer) String

func (b *Buffer) String() string

String returns a string copy of the underlying byte slice.

func (*Buffer) Write

func (b *Buffer) Write(bs []byte) (int, error)

Write implements io.Writer.

type BurstSampler

type BurstSampler = zerolog.BurstSampler

BurstSampler lets Burst events pass per Period then pass the decision to NextSampler. If Sampler is not set, all subsequent events are rejected.

type ConsoleConf

type ConsoleConf struct {
	Level   Level
	Format  string // empty or json
	NoColor bool
	Out     io.Writer
}

ConsoleConf is conf for console writer.

func (ConsoleConf) Write

func (w ConsoleConf) Write(p []byte) (n int, err error)

Write write data to writer.

func (ConsoleConf) WriteLevel

func (w ConsoleConf) WriteLevel(level Level, p []byte) (n int, err error)

WriteLevel write data to writer with level info provided

type Ctx

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

Ctx is a wrapper for *Log

func Sample

func Sample(sampler zerolog.Sampler) *Ctx

Sample logger

func WithContext

func WithContext(ctx ...context.Context) *Ctx

WithContext create a wrapped *Log

func (*Ctx) Debug

func (b *Ctx) Debug(name ...string) *Log

Debug level msg

func (*Ctx) Error

func (b *Ctx) Error(name ...string) *Log

Error level msg

func (*Ctx) Info

func (b *Ctx) Info(name ...string) *Log

Info level msg

func (*Ctx) KV

func (b *Ctx) KV(key string, val string) *Log

KV is log kv pairs.

func (*Ctx) Warn

func (b *Ctx) Warn(name ...string) *Log

Warn level msg

type Level

type Level = zerolog.Level // go1.9 type alias

Level type.

type LevelSampler

type LevelSampler = zerolog.LevelSampler

LevelSampler applies a different sampler for each level.

type Log

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

Log struct.

func Debug

func Debug(name ...string) *Log

Debug level msg

func Error

func Error(name ...string) *Log

Error level msg

func Info

func Info(name ...string) *Log

Info level msg

func NewLog

func NewLog() *Log

NewLog .

func NewLogger

func NewLogger(project, env, redisURL string, level zerolog.Level) *Log

NewLogger .

func Warn

func Warn(name ...string) *Log

Warn level msg

func (*Log) Context

func (b *Log) Context() context.Context

Context add wappered *Log to context

func (*Log) Error

func (b *Log) Error(args ...interface{})

Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.

func (*Log) Errorf

func (b *Log) Errorf(format string, args ...interface{})

Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.

func (*Log) Errorln

func (b *Log) Errorln(args ...interface{})

Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println.

func (*Log) Fatal

func (b *Log) Fatal(args ...interface{})

Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print. gRPC ensures that all Fatal logs will exit with os.Exit(1). Implementations may also call os.Exit() with a non-zero exit code.

func (*Log) Fatalf

func (b *Log) Fatalf(format string, args ...interface{})

Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. gRPC ensures that all Fatal logs will exit with os.Exit(1). Implementations may also call os.Exit() with a non-zero exit code.

func (*Log) Fatalln

func (b *Log) Fatalln(args ...interface{})

Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println. gRPC ensures that all Fatal logs will exit with os.Exit(1). Implementations may also call os.Exit() with a non-zero exit code.

func (*Log) Info

func (b *Log) Info(args ...interface{})

Info logs to INFO log. Arguments are handled in the manner of fmt.Print.

func (*Log) Infof

func (b *Log) Infof(format string, args ...interface{})

Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.

func (*Log) Infoln

func (b *Log) Infoln(args ...interface{})

Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println.

func (*Log) KV

func (b *Log) KV(key string, val string) *Log

KV is log kv pairs.

func (*Log) Msg

func (b *Log) Msg(msg ...interface{})

Msg output

func (*Log) Msgf

func (b *Log) Msgf(msg string, v ...interface{})

Msgf formatted output

func (*Log) Printf

func (b *Log) Printf(format string, args ...interface{})

Printf logs to INFO log. Arguments are handled in the manner of fmt.Printf.

func (*Log) Stack

func (b *Log) Stack() *Log

Stack enables stack trace

func (*Log) TraceID

func (b *Log) TraceID(traceId string) *Log

func (*Log) V

func (b *Log) V(l int) bool

V reports whether verbosity level l is at least the requested verbose level.

func (*Log) Warning

func (b *Log) Warning(args ...interface{})

Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print.

func (*Log) Warningf

func (b *Log) Warningf(format string, args ...interface{})

Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.

func (*Log) Warningln

func (b *Log) Warningln(args ...interface{})

Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println.

type Pool

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

A Pool is a type-safe wrapper around a sync.Pool.

func NewBytesPool

func NewBytesPool(optionalSize ...int) Pool

NewPool constructs a new Pool.

func (Pool) Get

func (p Pool) Get() *Buffer

Get retrieves a Buffer from the pool, creating one if necessary.

type RedisConfig

type RedisConfig struct {
	Level     Level
	RedisURL  string
	RedisPass string
	LogKey    string
	// contains filtered or unexported fields
}

RedisConfig is conf for redis writer.

func (RedisConfig) Write

func (c RedisConfig) Write(p []byte) (n int, err error)

Write write data to writer

func (RedisConfig) WriteLevel

func (c RedisConfig) WriteLevel(level Level, p []byte) (n int, err error)

WriteLevel write data to writer with level info provided

type Sampler

type Sampler = zerolog.Sampler

Sampler is zerolog Sampler alias

type Writer

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

Writer is a io.Writer wrapper that uses a diode to make Write lock-free, non-blocking and thread safe.

func NewAsyncWriter

func NewAsyncWriter(l Level, w io.Writer, manyToOneDiode *diodes.ManyToOne, poolInterval time.Duration) Writer

NewAsyncWriter creates a writer wrapping w with a many-to-one diode in order to never block log producers and drop events if the writer can't keep up with the flow of data.

Use a diode.Writer when

d := diodes.NewManyToOne(1000, diodes.AlertFunc(func(missed int) {
    log.Printf("Dropped %d messages", missed)
}))
w := diode.NewWriter(w, d, 10 * time.Millisecond)
log := zerolog.New(w)

See code.cloudfoundry.org/go-diodes for more info on diode.

func (Writer) Close

func (dw Writer) Close() error

Close releases the diode poller and call Close on the wrapped writer if io.Closer is implemented.

func (Writer) Write

func (dw Writer) Write(p []byte) (n int, err error)

Write write data to writer

func (Writer) WriteLevel

func (dw Writer) WriteLevel(level Level, p []byte) (n int, err error)

WriteLevel write data to writer with level info provided

Jump to

Keyboard shortcuts

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