logger

package
v0.0.0-...-e9f0680 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicLogger

type BasicLogger struct {
	// contains filtered or unexported fields
}

BasicLogger simply implements Logger

func (*BasicLogger) Debug

func (b *BasicLogger) Debug(fields map[string]interface{}, format string, args ...interface{})

Debug Log print a message with debug level.

func (*BasicLogger) DebugWithTime

func (b *BasicLogger) DebugWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})

DebugWithTime implements Logger

func (*BasicLogger) Error

func (b *BasicLogger) Error(fields map[string]interface{}, format string, args ...interface{})

Error Log print a message with error level.

func (*BasicLogger) ErrorWithTime

func (b *BasicLogger) ErrorWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})

ErrorWithTime implements Logger

func (*BasicLogger) Fatal

func (b *BasicLogger) Fatal(fields map[string]interface{}, format string, args ...interface{})

Fatal Log print a message with fatal level.

func (*BasicLogger) FatalWithTime

func (b *BasicLogger) FatalWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})

FatalWithTime implements Logger

func (*BasicLogger) GetCurrentLevel

func (b *BasicLogger) GetCurrentLevel() string

func (*BasicLogger) Info

func (b *BasicLogger) Info(fields map[string]interface{}, format string, args ...interface{})

Info Log print a message with info level.

func (*BasicLogger) InfoWithTime

func (b *BasicLogger) InfoWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})

InfoWithTime implements Logger

func (*BasicLogger) NewLogger

func (b *BasicLogger) NewLogger(component string) Logger

NewLogger is used to derive a new child Logger

func (*BasicLogger) SetLogLevel

func (b *BasicLogger) SetLogLevel(verbosity string)

SetLogLevel is used to set log level

func (*BasicLogger) Trace

func (b *BasicLogger) Trace(fields map[string]interface{}, format string, args ...interface{})

Trace Log print a message with debug level.

func (*BasicLogger) TraceWithTime

func (b *BasicLogger) TraceWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})

TraceWithTime implements Logger

func (*BasicLogger) Warn

func (b *BasicLogger) Warn(fields map[string]interface{}, format string, args ...interface{})

Warn Log print a message with warn level.

func (*BasicLogger) WarnWithTime

func (b *BasicLogger) WarnWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})

WarnWithTime implements Logger

func (*BasicLogger) WithContext

func (b *BasicLogger) WithContext(ctx context.Context) TraceLogger

WithContext implements Logger

type CallerHook

type CallerHook struct{}

CallerHook implements zerolog.Hook interface.

func (CallerHook) Run

func (h CallerHook) Run(e *zerolog.Event, level zerolog.Level, msg string)

Run adds additional context

type Config

type Config struct {
	Pretty bool   `yaml:"prefix"`
	Level  string `yaml:"level"`
}

Config defines the config structure

func NewConfig

func NewConfig() *Config

NewConfig is used to init config with default values

func (*Config) RegisterFlagsWithPrefix

func (c *Config) RegisterFlagsWithPrefix(prefix string, f *pflag.FlagSet)

RegisterFlagsWithPrefix is used to register flags

func (*Config) Validate

func (c *Config) Validate() error

type Logger

type Logger interface {
	// Trace print a message with trace level.
	Trace(fields map[string]interface{}, format string, args ...interface{})
	// Debug print a message with debug level.
	Debug(fields map[string]interface{}, format string, args ...interface{})
	// Info print a message with info level.
	Info(fields map[string]interface{}, format string, args ...interface{})
	// Warn print a message with warn level.
	Warn(fields map[string]interface{}, format string, args ...interface{})
	// Error print a message with error level.
	Error(fields map[string]interface{}, format string, args ...interface{})
	// Fatal print a message with fatal level.
	Fatal(fields map[string]interface{}, format string, args ...interface{})

	// Trace print a message with trace level.
	TraceWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})
	// Debug print a message with debug level.
	DebugWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})
	// Info print a message with info level.
	InfoWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})
	// Warn print a message with warn level.
	WarnWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})
	// Error print a message with error level.
	ErrorWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})
	// Fatal print a message with fatal level.
	FatalWithTime(logTime time.Time, fields map[string]interface{}, format string, args ...interface{})

	// WithContext trade log.
	WithContext(ctx context.Context) TraceLogger

	// NewLogger is used to derive a new child Logger
	NewLogger(component string) Logger
	// SetLogLevel is used to set log level
	SetLogLevel(verbosity string)

	GetCurrentLevel() string
}

Logger defines the basic log library implementation

func New

func New(cfg *Config, component string) (Logger, error)

New is used to init service

func NewDefault

func NewDefault(component string) Logger

NewDefault is used to initialize a simple Logger

type Message

type Message struct {
	Format string
	Fields map[string]interface{}
	Args   []interface{}
	Time   time.Time
	Level  zerolog.Level
	// contains filtered or unexported fields
}

type TraceLogger

type TraceLogger interface {
	Logger
	// Begin begin build trace id.
	Begin() context.Context
	// output trace log.
	Done()
}

Jump to

Keyboard shortcuts

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