logger

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

logger package

Here we use Zerolog for logging (https://github.com/rs/zerolog). zerolog is a json based logger that is lightning fast and efficient in production code. See its benchmark for reference. With json based logger, all logs and errors can be easily parsed and analyzed from all servers.

Usage

import "logger"
logger.Debug().Str("StrKey", "StrValue").Float("FloatKey", float_number).Msg("Your msg");

There are different levels of logging in this logger

logger.Debug()
logger.Info()
logger.Warn()
logger.Error()
logger.Fatal()
logger.Panic()

Starting from Error level, you can use a Err() func to put your Err return. Example

logger.Error().Err(err).Msg("something is wrong!")

A Msg() func call is required to send out the the msg.

For more advanced features, please refer to https://github.com/rs/zerolog

Info is the default threshold of logs to output. Use -log-level=[info] on command line to override the level.

Logs are output to stderr by default. Us -log-path=[path] on command line to override the path.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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

func Logger() *zerolog.Logger

Logger gets the global logger client instance.

func New added in v0.3.0

func New() (zerolog.Logger, error)

New creates a new zerolog instance.

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 Sample

func Sample(s zerolog.Sampler) zerolog.Logger

Sample returns a logger with the s sampler.

func SetLogger

func SetLogger(l zerolog.Logger)

SetLogger sets the global logger client pointer to arbitrary logger client instance

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.

Jump to

Keyboard shortcuts

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