log

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LoggerWithoutCaller = zerolog.New(os.Stderr).With().Timestamp().Logger()
	Logger              = LoggerWithoutCaller.With().Caller().Logger()
)

Logger is the global logger.

Functions

func Ctx

func Ctx(ctx context.Context) *zerolog.Logger

Ctx returns the Logger associated with the ctx. If no logger is associated, a disabled logger is returned.

func Debug

func Debug() *zerolog.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

func Err(err error) *zerolog.Event

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 Error

func Error() *zerolog.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() *zerolog.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 FromRequest

func FromRequest(r *http.Request) *zerolog.Logger

func Hook

func Hook(h zerolog.Hook) zerolog.Logger

Hook returns a logger with the h Hook.

func IDFromCtx

func IDFromCtx(ctx context.Context) (id xid.ID, ok bool)

IDFromCtx returns the unique id associated to the context if any.

func Info

func Info() *zerolog.Event

Info starts a new message with info level.

You must call Msg on the returned event in order to send the event.

func InstanceFromCtx

func InstanceFromCtx(ctx context.Context) (id xid.ID, ok bool)

InstanceFromCtx returns the unique id associated to the context if any.

func Level

func Level(level zerolog.Level) zerolog.Logger

Level creates a child logger with the minimum accepted level set to level.

func Log

func Log() *zerolog.Event

Log starts a new message with no level. Setting zerolog.GlobalLevel to zerolog.Disabled will still disable events produced by this method.

You must call Msg on the returned event in order to send the event.

func Output

func Output(w io.Writer) zerolog.Logger

Output duplicates the global logger and sets w as its output.

func Panic

func Panic() *zerolog.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 Print

func Print(v ...interface{})

Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.

func Printf

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

Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.

func Sample

func Sample(s zerolog.Sampler) zerolog.Logger

Sample returns a logger with the s sampler.

func SetBlockingLogger

func SetBlockingLogger(w io.Writer)

SetBlockingLogger sets up a logger with a non blocking writer

func SetConsoleLogger

func SetConsoleLogger()

SetConsoleLogger sets up logging for console logging (developmnet)

func SetDiscardLogger

func SetDiscardLogger()

SetDiscardLogger sets global log level to trace and log to a ioutil.Discard writer. Use in tests to ensure that writing logs don't panic and are sileced.

func SetSimpleConsoleLogger

func SetSimpleConsoleLogger()

SetSimpleConsoleLogger sets up logging for console logging to cli tool end users

func SetVerboseTestingConsoleLogger

func SetVerboseTestingConsoleLogger(level zerolog.Level)

SetVerboseTestingConsoleLogger

func Trace

func Trace() *zerolog.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() *zerolog.Event

Warn starts a new message with warn level.

You must call Msg on the returned event in order to send the event.

func With

func With() zerolog.Context

With creates a child logger with the field added to its context.

func WithID

func WithID(ctx context.Context) zerolog.Context

With creates a child logger with the field added to its context.

func WithIDContext

func WithIDContext(ctx context.Context) context.Context
 Adds a logger and an request id to the context.Context.

 To create and use a new context/logger:

 	ctx = log.WithIDContext(ctx)
		logger := log.WithID(ctx).Logger()

func WithIDWithoutCaller

func WithIDWithoutCaller(ctx context.Context) zerolog.Context

func WithInstanceContext

func WithInstanceContext(ctx context.Context) context.Context

func WithLevel

func WithLevel(level zerolog.Level) *zerolog.Event

WithLevel starts a new message with level.

You must call Msg on the returned event in order to send the event.

Types

type Config

type Config struct {
	Debug          bool
	Trace          bool
	Console        bool
	FileName       string
	FileMaxBackups int
	FileMaxSize    int
	FileMaxAge     int
}

Config is a collection of stdlib flags configuring logging

func (*Config) RegisterFlags

func (f *Config) RegisterFlags(fs *flag.FlagSet)

RegisterFlags registers the flags in a flag.FlagSet with default for json logging

func (*Config) RegisterFlagsConsole

func (f *Config) RegisterFlagsConsole(fs *flag.FlagSet)

Register registers the flags in a flag.FlagSet with defaults for console logging

func (Config) Setup

func (f Config) Setup() error

Setup sets up logging accorind to Flags values.

Jump to

Keyboard shortcuts

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