Documentation ¶
Overview ¶
Package log provides a structured context logger.
Index ¶
- func AddGlobalFields(field string)
- func ClearGlobalFields()
- func Debug() *zerolog.Event
- func Error(err error) *zerolog.Event
- func Fatal(err error) *zerolog.Event
- func GetGlobalFields() []string
- func Goid() uint64
- func Info() *zerolog.Event
- func Log() *zerolog.Event
- func Panic() *zerolog.Event
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func ResetGlobalStorage()
- func ScCallerEncoder() func(file string, line int) string
- func ScLevelEncoder() func(l zerolog.Level) string
- func SetGlobalFields(fields []string)
- func Trace() *zerolog.Event
- func TrimmedPath(file string) string
- func Warn() *zerolog.Event
- func Z() *zerolog.Logger
- type Logger
- type MapperHook
- type Storage
- func (s *Storage) Count() int
- func (s *Storage) Get(key string) (interface{}, bool)
- func (s *Storage) GetString(key string) string
- func (s *Storage) Has(key string) bool
- func (s *Storage) IsEmpty() bool
- func (s *Storage) Keys() []string
- func (s *Storage) Remove(key string)
- func (s *Storage) Set(key string, value interface{})
- func (s *Storage) SetAbsent(key string, value interface{}) bool
- func (s *Storage) SetMap(mp map[string]interface{})
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddGlobalFields ¶
func AddGlobalFields(field string)
func ClearGlobalFields ¶
func ClearGlobalFields()
func Debug ¶
Example ¶
package main import ( "os" "time" "github.com/Iridaceae/iridaceae/pkg/log" "github.com/rs/zerolog" ) var hookFunc = log.MapperHook{} func setup() { zerolog.TimeFieldFormat = "" zerolog.TimestampFunc = func() time.Time { return time.Date(2020, 4, 20, 4, 20, 0o4, 0, time.UTC) } zlog := zerolog.New(os.Stdout).With().Timestamp().Logger().Hook(hookFunc) log.L = log.NewZ(zlog) } func main() { setup() log.Debug().Msg("hello world") }
Output: {"level":"DEBUG","time":1587356404,"message":"hello world"}
func GetGlobalFields ¶
func GetGlobalFields() []string
func Goid ¶
func Goid() uint64
Goid returns a goroutine id of given stack trace. As the word of the wise Dave Cheney you might as well go to hell by using this. This is a hacky pure Go version of dave cheney's implementation.
func Log ¶
Example ¶
package main import ( "os" "time" "github.com/Iridaceae/iridaceae/pkg/log" "github.com/rs/zerolog" ) var hookFunc = log.MapperHook{} func setup() { zerolog.TimeFieldFormat = "" zerolog.TimestampFunc = func() time.Time { return time.Date(2020, 4, 20, 4, 20, 0o4, 0, time.UTC) } zlog := zerolog.New(os.Stdout).With().Timestamp().Logger().Hook(hookFunc) log.L = log.NewZ(zlog) } func main() { setup() log.Log().Msg("hello world") }
Output: {"time":1587356404,"message":"hello world"}
func Print ¶
func Print(args ...interface{})
Example ¶
package main import ( "os" "time" "github.com/Iridaceae/iridaceae/pkg/log" "github.com/rs/zerolog" ) var hookFunc = log.MapperHook{} func setup() { zerolog.TimeFieldFormat = "" zerolog.TimestampFunc = func() time.Time { return time.Date(2020, 4, 20, 4, 20, 0o4, 0, time.UTC) } zlog := zerolog.New(os.Stdout).With().Timestamp().Logger().Hook(hookFunc) log.L = log.NewZ(zlog) } func main() { setup() log.Print("hello world") }
Output: {"level":"DEBUG","time":1587356404,"message":"hello world"}
func Printf ¶
func Printf(format string, args ...interface{})
Example ¶
package main import ( "os" "time" "github.com/Iridaceae/iridaceae/pkg/log" "github.com/rs/zerolog" ) var hookFunc = log.MapperHook{} func setup() { zerolog.TimeFieldFormat = "" zerolog.TimestampFunc = func() time.Time { return time.Date(2020, 4, 20, 4, 20, 0o4, 0, time.UTC) } zlog := zerolog.New(os.Stdout).With().Timestamp().Logger().Hook(hookFunc) log.L = log.NewZ(zlog) } func main() { setup() log.Printf("hello %s", "world") }
Output: {"level":"DEBUG","time":1587356404,"message":"hello world"}
func ScCallerEncoder ¶
func ScLevelEncoder ¶
func SetGlobalFields ¶
func SetGlobalFields(fields []string)
func Trace ¶
Example ¶
package main import ( "os" "time" "github.com/Iridaceae/iridaceae/pkg/log" "github.com/rs/zerolog" ) var hookFunc = log.MapperHook{} func setup() { zerolog.TimeFieldFormat = "" zerolog.TimestampFunc = func() time.Time { return time.Date(2020, 4, 20, 4, 20, 0o4, 0, time.UTC) } zlog := zerolog.New(os.Stdout).With().Timestamp().Logger().Hook(hookFunc) log.L = log.NewZ(zlog) } func main() { setup() log.Trace().Msg("hello world") }
Output: {"level":"TRACE","time":1587356404,"message":"hello world"}
func TrimmedPath ¶
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger defines a default logger for that wraps around rs/zerolog.
var L *Logger
func New ¶
func New() *Logger
New returns a default Logger wrapped around zerolog.
Example ¶
package main import ( "os" "time" "github.com/Iridaceae/iridaceae/pkg/log" "github.com/rs/zerolog" ) var hookFunc = log.MapperHook{} func setup() { zerolog.TimeFieldFormat = "" zerolog.TimestampFunc = func() time.Time { return time.Date(2020, 4, 20, 4, 20, 0o4, 0, time.UTC) } zlog := zerolog.New(os.Stdout).With().Timestamp().Logger().Hook(hookFunc) log.L = log.NewZ(zlog) } func main() { log.New() setup() log.Info().Msg("hello world") }
Output: {"level":"INFO","time":1587356404,"message":"hello world"}
type MapperHook ¶
type MapperHook struct{}
type Storage ¶
Storage defines our key, value mapping for our context. Storage is inherently safe for concurrency and goroutines.
func InitGlobalStorage ¶
func InitGlobalStorage() *Storage
InitGlobalStorage initializes a Storage objects with a key,value map.
Click to show internal directories.
Click to hide internal directories.