logger

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 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 Init

func Init(cfg Logging) (err error)

Init initializes a rs/zerolog logger from user config.

func Proto added in v0.3.0

func Proto(message proto.Message) []byte

Proto converts proto.Message to JSON raw data.

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