logger

package
v0.0.0-...-6ea431b Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggerExample

func LoggerExample()

func LoggerV1Example

func LoggerV1Example()

func LoggerV2Example

func LoggerV2Example()

func SetGlobalLogger

func SetGlobalLogger(l LoggerV1)

Types

type Field

type Field struct {
	Key   string
	Value any
}

func Error

func Error(err error) Field

func Int32

func Int32(key string, val int32) Field

func Int64

func Int64(key string, val int64) Field

func String

func String(key, val string) Field

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

实践1

type LoggerV1

type LoggerV1 interface {
	Debug(msg string, args ...Field)
	Info(msg string, args ...Field)
	Warn(msg string, args ...Field)
	Error(msg string, args ...Field)
}

实践2

var GL LoggerV1 = &NoOpLogger{}

func L

func L() LoggerV1

func NewNoOpLogger

func NewNoOpLogger() LoggerV1

type LoggerV2

type LoggerV2 interface {
	// args 必须是偶数,并且按照 key-value, key-value 来组织
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

实践3

type NoOpLogger

type NoOpLogger struct {
}

func (*NoOpLogger) Debug

func (n *NoOpLogger) Debug(msg string, args ...Field)

func (*NoOpLogger) Error

func (n *NoOpLogger) Error(msg string, args ...Field)

func (*NoOpLogger) Info

func (n *NoOpLogger) Info(msg string, args ...Field)

func (*NoOpLogger) Warn

func (n *NoOpLogger) Warn(msg string, args ...Field)

type ZapLogger

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

func NewZapLogger

func NewZapLogger(l *zap.Logger) *ZapLogger

func (*ZapLogger) Debug

func (z *ZapLogger) Debug(msg string, args ...Field)

func (*ZapLogger) Error

func (z *ZapLogger) Error(msg string, args ...Field)

func (*ZapLogger) Info

func (z *ZapLogger) Info(msg string, args ...Field)

func (*ZapLogger) Warn

func (z *ZapLogger) Warn(msg string, args ...Field)

Jump to

Keyboard shortcuts

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