logger

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package logger implements a logging system with a module tag. The module tag represents a scope where the log event is emitted.

Index

Constants

This section is empty.

Variables

View Source
var ContextKey = contextKey{}

ContextKey is the key to store Logger in the context.

Functions

func Debugf added in v0.6.0

func Debugf(f string, v ...interface{})

Debugf logs a message at the debug level. It uses sprintf-style formatting for its message.

func Errorf added in v0.6.0

func Errorf(f string, v ...interface{})

Errorf logs a message at the error level. It uses sprintf-style formatting for its message.

func Infof added in v0.6.0

func Infof(f string, v ...interface{})

Infof logs a message at the info level. It uses sprintf-style formatting for its message.

func Init

func Init(cfg Logging) (err error)

Init initializes a rs/zerolog logger from user config.

func Panicf added in v0.6.0

func Panicf(f string, v ...interface{})

Panicf logs a message at the panic level. It panics after logging the message. It uses sprintf-style formatting for its message.

func Proto added in v0.3.0

func Proto(message proto.Message) []byte

Proto converts proto.Message to JSON raw data.

func Warningf added in v0.6.0

func Warningf(f string, v ...interface{})

Warningf logs a message at the warning level. It uses sprintf-style formatting for its message.

Types

type Loggable

type Loggable interface {
	SetLogger(*Logger)
}

Loggable indicates the implement supports logging.

type Logger

type Logger struct {
	*zerolog.Logger
	// contains filtered or unexported fields
}

Logger is wrapper for rs/zerolog logger with module, it is singleton.

func Fetch

func Fetch(ctx context.Context, newModuleName string) *Logger

Fetch gets a Logger in a context, then creates a new Logger based on it.

func FetchOrDefault added in v0.3.0

func FetchOrDefault(ctx context.Context, newModuleName string, defaultLogger *Logger) *Logger

FetchOrDefault gets a Logger in a context, then creates a new Logger based on it If the context doesn't include a Logger. The default Logger will be picked.

func GetLogger

func GetLogger(scope ...string) *Logger

GetLogger return logger with a scope.

func (Logger) Module added in v0.2.0

func (l Logger) Module() string

Module returns logger's module name.

func (*Logger) Named

func (l *Logger) Named(name ...string) *Logger

Named creates a new Logger and assigns a module to it.

func (*Logger) Sampled added in v0.3.0

func (l *Logger) Sampled(n uint32) *Logger

Sampled return a Logger with a sampler that will send every Nth events.

func (*Logger) ToZapConfig added in v0.3.0

func (l *Logger) ToZapConfig() zap.Config

ToZapConfig outputs the zap config is derived from l.

type Logging

type Logging struct {
	Env     string
	Level   string
	Modules []string
	Levels  []string
}

Logging is the config info.

type MarshalError added in v0.3.0

type MarshalError struct {
	Msg string `json:"msg"`
}

MarshalError is the error raised by marshaling a JSON object.

Jump to

Keyboard shortcuts

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