log

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Console

func Console()

Console sets output to be human-readable

func CopyContext

func CopyContext(ctx context.Context, dst context.Context) context.Context

CopyContext returns a context derived from dst that contains the eventual logging keys that are contained in ctx

func Exec

func Exec(ctx context.Context, cmd *exec.Cmd, options ...ExecOption) error

Exec wraps os/exec for logging its outputs. If cmd.Stdout is not set, the commands stdout will be sent to log.Logger(ctx) (at Info level by default). If cmd.Stderr is not set, the commands stderr will be sent to log.Logger(ctx) (at Warn level by default). On ctx cancellation, the cmd is Killed

func Fatal

func Fatal(v ...interface{})

func Fatalf

func Fatalf(format string, v ...interface{})

func Logger

func Logger(ctx context.Context) *zap.Logger

Logger returns a logger that will print fields previously added to the context

func Panic

func Panic(v ...interface{})

func Panicf

func Panicf(msg string, v ...interface{})

func Print

func Print(v ...interface{})

Print logs at Info level

func Printf

func Printf(format string, v ...interface{})

Printf logs at Info level

func Println

func Println(v ...interface{})

func Structured

func Structured()

Structured sets output to be JSON encoded

func With

func With(ctx context.Context, key string, value interface{}) context.Context

With adds a key=value field to the returned context

func WithFields

func WithFields(ctx context.Context, fields ...zapcore.Field) context.Context

WithFields adds fields to the returned context

Types

type ExecOption

type ExecOption func(eo *execOption)

ExecOption is an option that can be passed to Exec()

func StderrFilter

func StderrFilter(f Filter) ExecOption

StderrFilter sets a function that modify a stderr message or change its level

func StderrLevel

func StderrLevel(l zapcore.Level) ExecOption

StderrLevel sets the level at which stderr should be logged

func StdoutFilter

func StdoutFilter(f Filter) ExecOption

StdoutFilter sets a function that modify a stdout message or change its level

func StdoutLevel

func StdoutLevel(l zapcore.Level) ExecOption

StdoutLevel sets the level at which stdout should be logged

type Filter

type Filter interface {
	Filter(msg string, defaultLevel zapcore.Level) (string, zapcore.Level, bool)
}

Filter receives a message and the default level and returns a modified message with a new level if the last result is true, the msg is ignored

Jump to

Keyboard shortcuts

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