logger

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 7 Imported by: 2

README

日志组件

封装zap作为日志组件, 可推送至loki

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger *zap.Logger) context.Context

func Ctx

func Ctx(ctx context.Context) *zap.Logger

func Default

func Default() *zap.Logger

Default 默认日志,尽量不要使用,会丢失上下文信息

func Logger

func Logger(ctx context.Context, config *configs.Config) error

Logger 日志组件,核心组件,必须提前注册

func New

func New(opt ...Option) (*zap.Logger, error)

func NewFileCore

func NewFileCore(level zapcore.Level, filename string) zapcore.Core

func RegistryInitLogger

func RegistryInitLogger(f InitLogger)

func SetLogger

func SetLogger(l *zap.Logger)

func ToLevel

func ToLevel(level string) zapcore.Level

Types

type Config

type Config struct {
	Level          string
	DisableConsole bool          `yaml:"disableConsole"`
	LogFile        LogFileConfig `yaml:"logFile"`
}

type CtxLogger

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

func NewCtxLogger

func NewCtxLogger(logger *zap.Logger) *CtxLogger

func (*CtxLogger) Ctx

func (c *CtxLogger) Ctx(ctx context.Context) *CtxLogger

func (*CtxLogger) With

func (c *CtxLogger) With(fields ...zap.Field) *CtxLogger

type InitLogger

type InitLogger func(ctx context.Context, config *configs.Config, loggerConfig *Config) ([]Option, error)

type LogFileConfig

type LogFileConfig struct {
	Enable        bool
	Filename      string
	ErrorFilename string `yaml:"errorFilename"`
}

type Option

type Option func(*Options)

func AppendCore

func AppendCore(core ...zapcore.Core) Option

func Level

func Level(level string) Option

func WithWriter

func WithWriter(w io.Writer) Option

type Options

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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