deferlog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2021 License: MIT Imports: 9 Imported by: 0

README

deferlog

deferlog provide a useful toolset for rs/zerolog.

default config

  1. use console logger while running in a terminal
  2. use json logger while log into file (such as running in container)
  3. read the environement LOG_LEVEL to change default log level

Defer logger example

func example() (err error) {
	start := time.Now()
	defer func() {
		deferlog.DebugWarn(err).
			Dur("took", time.Since(start)).
			Msg("run the example function")
	}()

    // do something here

	return nil
}

Documentation

Overview

Package log provides a global logger for zerolog.

Index

Constants

This section is empty.

Variables

View Source
var ConsoleLogger = zerolog.New(
	zerolog.ConsoleWriter{
		Out:        os.Stdout,
		TimeFormat: time.StampMilli,
	}).
	With().Timestamp().Stack().Logger()
View Source
var Logger = zerolog.New(os.Stderr).With().Timestamp().Logger()

Logger is the global logger.

View Source
var StdLogger zerolog.Logger
View Source
var StructLogger = zerolog.New(os.Stdout).
	With().Timestamp().Stack().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 DebugError

func DebugError(err error) *zerolog.Event

func DebugFatal

func DebugFatal(err error) *zerolog.Event

func DebugWarn

func DebugWarn(err error) *zerolog.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 Hook

func Hook(h zerolog.Hook) zerolog.Logger

Hook returns a logger with the h Hook.

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 InfoError added in v0.2.0

func InfoError(err error) *zerolog.Event

func InfoFatal

func InfoFatal(err error) *zerolog.Event

func InfoWarn

func InfoWarn(err error) *zerolog.Event

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 ShortCaller added in v0.1.1

func ShortCaller(line string) string

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 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

This section is empty.

Directories

Path Synopsis
Package log provides a global logger for zerolog.
Package log provides a global logger for zerolog.

Jump to

Keyboard shortcuts

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