log

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLoggerLevel

func SetLoggerLevel(level zerolog.Level)

SetLoggerLevel sets the log level of logger.

func SetLoggerOutput

func SetLoggerOutput(w io.Writer)

SetLoggerOutput sets the output of logger.

func UseColorLogger

func UseColorLogger()

UseColorLogger will writes the logs to stderr with colorful pretty format.

func UseConsoleLogger

func UseConsoleLogger()

UseConsoleLogger will writes the logs to stderr with pretty format without color.

Example
package main

import (
	"github.com/rs/zerolog"
	"github.com/tuotoo/biu/log"
)

func main() {
	log.UseConsoleLogger()
	log.Debug().Msg("hello")
	log.SetLoggerLevel(zerolog.InfoLevel)
	log.Debug().Msg("hello")
	log.Info().Int("int", 1).Msg("hello")
}
Output:

Types

type ColorWriter

type ColorWriter struct {
	WithColor bool
}

ColorWriter is a writer for writing pretty log to console

func (ColorWriter) Write

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

Write implements io.Writer

type Wrap added in v0.4.3

type Wrap struct {
	*zerolog.Event
	Level zerolog.Level
}

func Debug

func Debug() *Wrap

Debug starts a new log with debug level.

func Error

func Error() *Wrap

Error starts a new log with error level.

func Fatal

func Fatal() *Wrap

Fatal starts a new log with fatal level.

func Info

func Info() *Wrap

Info starts a new log with info level.

func Panic

func Panic() *Wrap

Panic starts a new log with panic level.

func Warn

func Warn() *Wrap

Warn starts a new log with warn level.

func (*Wrap) AnErr added in v0.4.3

func (l *Wrap) AnErr(key string, err error) *Wrap

AnErr adds the field key with err as a string to the *Event context. If err is nil, no field is added.

func (*Wrap) Array added in v0.4.3

func (l *Wrap) Array(key string, arr zerolog.LogArrayMarshaler) *Wrap

Array adds the field key with an array to the event context. Use zerolog.Arr() to create the array or pass a type that implement the LogArrayMarshaler interface.

func (*Wrap) Bool added in v0.4.3

func (l *Wrap) Bool(key string, b bool) *Wrap

Bool adds the field key with val as a bool to the *Event context.

func (*Wrap) Bools added in v0.4.3

func (l *Wrap) Bools(key string, b []bool) *Wrap

Bools adds the field key with val as a []bool to the *Event context.

func (*Wrap) Bytes added in v0.4.3

func (l *Wrap) Bytes(key string, val []byte) *Wrap

Bytes adds the field key with val as a string to the *Event context.

Runes outside of normal ASCII ranges will be hex-encoded in the resulting JSON.

func (*Wrap) Dur added in v0.4.3

func (l *Wrap) Dur(key string, d time.Duration) *Wrap

Dur adds the field key with duration d stored as zerolog.DurationFieldUnit. If zerolog.DurationFieldInteger is true, durations are rendered as integer instead of float.

func (*Wrap) Durs added in v0.4.3

func (l *Wrap) Durs(key string, d []time.Duration) *Wrap

Durs adds the field key with duration d stored as zerolog.DurationFieldUnit. If zerolog.DurationFieldInteger is true, durations are rendered as integer instead of float.

func (*Wrap) Err added in v0.4.3

func (l *Wrap) Err(err error) *Wrap

Err adds the field "error" with err as a string to the *Event context. If err is nil, no field is added. To customize the key name, change zerolog.ErrorFieldName.

func (*Wrap) Errs added in v0.4.3

func (l *Wrap) Errs(key string, errs []error) *Wrap

Errs adds the field key with errs as an array of strings to the *Event context. If err is nil, no field is added.

func (*Wrap) Fields added in v0.4.3

func (l *Wrap) Fields(fields map[string]interface{}) *Wrap

Fields is a helper function to use a map to set fields using type assertion.

func (*Wrap) Float32 added in v0.4.3

func (l *Wrap) Float32(key string, f float32) *Wrap

Float32 adds the field key with f as a float32 to the *Event context.

func (*Wrap) Float64 added in v0.4.3

func (l *Wrap) Float64(key string, f float64) *Wrap

Float64 adds the field key with f as a float64 to the *Event context.

func (*Wrap) Floats32 added in v0.4.3

func (l *Wrap) Floats32(key string, f []float32) *Wrap

Floats32 adds the field key with f as a []float32 to the *Event context.

func (*Wrap) Floats64 added in v0.4.3

func (l *Wrap) Floats64(key string, f []float64) *Wrap

Floats64 adds the field key with f as a []float64 to the *Event context.

func (*Wrap) Int added in v0.4.3

func (l *Wrap) Int(key string, i int) *Wrap

Int adds the field key with i as a int to the *Event context.

func (*Wrap) Int16 added in v0.4.3

func (l *Wrap) Int16(key string, i int16) *Wrap

Int16 adds the field key with i as a int16 to the *Event context.

func (*Wrap) Int32 added in v0.4.3

func (l *Wrap) Int32(key string, i int32) *Wrap

Int32 adds the field key with i as a int32 to the *Event context.

func (*Wrap) Int64 added in v0.4.3

func (l *Wrap) Int64(key string, i int64) *Wrap

Int64 adds the field key with i as a int64 to the *Event context.

func (*Wrap) Int8 added in v0.4.3

func (l *Wrap) Int8(key string, i int8) *Wrap

Int8 adds the field key with i as a int8 to the *Event context.

func (*Wrap) Interface added in v0.4.3

func (l *Wrap) Interface(key string, i interface{}) *Wrap

Interface adds the field key with i marshaled using reflection.

func (*Wrap) Ints added in v0.4.3

func (l *Wrap) Ints(key string, i []int) *Wrap

Ints adds the field key with i as a []int to the *Event context.

func (*Wrap) Ints16 added in v0.4.3

func (l *Wrap) Ints16(key string, i []int16) *Wrap

Ints16 adds the field key with i as a []int16 to the *Event context.

func (*Wrap) Ints32 added in v0.4.3

func (l *Wrap) Ints32(key string, i []int32) *Wrap

Ints32 adds the field key with i as a []int32 to the *Event context.

func (*Wrap) Ints64 added in v0.4.3

func (l *Wrap) Ints64(key string, i []int64) *Wrap

Ints64 adds the field key with i as a []int64 to the *Event context.

func (*Wrap) Ints8 added in v0.4.3

func (l *Wrap) Ints8(key string, i []int8) *Wrap

Ints8 adds the field key with i as a []int8 to the *Event context.

func (Wrap) Msg added in v0.4.3

func (l Wrap) Msg(msg string)

Msg sends the *Wrap with msg added as the message field if not empty.

NOTICE: once this method is called, the *Wrap should be disposed. Calling Msg twice can have unexpected result.

func (Wrap) Msgf added in v0.4.3

func (l Wrap) Msgf(format string, v ...interface{})

func (*Wrap) Object added in v0.4.3

func (l *Wrap) Object(key string, obj zerolog.LogObjectMarshaler) *Wrap

Object marshals an object that implement the LogObjectMarshaler interface.

func (*Wrap) Str added in v0.4.3

func (l *Wrap) Str(key, val string) *Wrap

Str adds the field key with val as a string to the *Event context.

func (*Wrap) Strs added in v0.4.3

func (l *Wrap) Strs(key string, vals []string) *Wrap

Strs adds the field key with vals as a []string to the *Event context.

func (*Wrap) Time added in v0.4.3

func (l *Wrap) Time(key string, t time.Time) *Wrap

Time adds the field key with t formated as string using zerolog.TimeFieldFormat.

func (*Wrap) TimeDiff added in v0.4.3

func (l *Wrap) TimeDiff(key string, t time.Time, start time.Time) *Wrap

TimeDiff adds the field key with positive duration between time t and start. If time t is not greater than start, duration will be 0. Duration format follows the same principle as Dur().

func (*Wrap) Times added in v0.4.3

func (l *Wrap) Times(key string, t []time.Time) *Wrap

Times adds the field key with t formated as string using zerolog.TimeFieldFormat.

func (*Wrap) Timestamp added in v0.4.3

func (l *Wrap) Timestamp() *Wrap

Timestamp adds the current local time as UNIX timestamp to the *Event context with the "time" key. To customize the key name, change zerolog.TimestampFieldName.

func (*Wrap) Uint added in v0.4.3

func (l *Wrap) Uint(key string, i uint) *Wrap

Uint adds the field key with i as a uint to the *Event context.

func (*Wrap) Uint16 added in v0.4.3

func (l *Wrap) Uint16(key string, i uint16) *Wrap

Uint16 adds the field key with i as a uint16 to the *Event context.

func (*Wrap) Uint32 added in v0.4.3

func (l *Wrap) Uint32(key string, i uint32) *Wrap

Uint32 adds the field key with i as a uint32 to the *Event context.

func (*Wrap) Uint64 added in v0.4.3

func (l *Wrap) Uint64(key string, i uint64) *Wrap

Uint64 adds the field key with i as a uint64 to the *Event context.

func (*Wrap) Uint8 added in v0.4.3

func (l *Wrap) Uint8(key string, i uint8) *Wrap

Uint8 adds the field key with i as a uint8 to the *Event context.

func (*Wrap) Uints added in v0.4.3

func (l *Wrap) Uints(key string, i []uint) *Wrap

Uints adds the field key with i as a []int to the *Event context.

func (*Wrap) Uints16 added in v0.4.3

func (l *Wrap) Uints16(key string, i []uint16) *Wrap

Uints16 adds the field key with i as a []int16 to the *Event context.

func (*Wrap) Uints32 added in v0.4.3

func (l *Wrap) Uints32(key string, i []uint32) *Wrap

Uints32 adds the field key with i as a []int32 to the *Event context.

func (*Wrap) Uints64 added in v0.4.3

func (l *Wrap) Uints64(key string, i []uint64) *Wrap

Uints64 adds the field key with i as a []int64 to the *Event context.

func (*Wrap) Uints8 added in v0.4.3

func (l *Wrap) Uints8(key string, i []uint8) *Wrap

Uints8 adds the field key with i as a []int8 to the *Event context.

Jump to

Keyboard shortcuts

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