logger

package
v0.0.44 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultLevel the default log level
	DefaultLevel     zapcore.Level = zapcore.InfoLevel
	DefaultLevelInt8 int8          = 0

	// DefaultTimeLayout the default time layout;
	DefaultTimeLayout = time.RFC3339
)

Variables

This section is empty.

Functions

func NewJSONLogger

func NewJSONLogger(opts ...Option) (*zap.Logger, error)

NewJSONLogger return a json-encoder zap logger,

func NewLogger

func NewLogger(text bool, opts ...Option) (*zap.Logger, error)

NewLogger return a json-encoder zap logger,

func NewTextLogger

func NewTextLogger(opts ...Option) (*zap.Logger, error)

NewTextLogger return a json-encoder zap logger,

func WrapMeta

func WrapMeta(err error, metas ...Meta) (fields []zap.Field)

WrapMeta wrap meta to zap fields

Types

type LogAppender

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

type LogAppenderCfg

type LogAppenderCfg struct {
	NoCaller *bool  `yaml:"noCaller,omitempty"` //
	Disabled *bool  `yaml:"disabled,omitempty"` // disabled
	Text     *bool  `yaml:"text,omitempty"`     // json or text format
	Level    *int8  `yaml:"level,omitempty"`    // int8 ? zapcore.Level yml格式化输出会输出debug这种字符串,parse然后得不到正确是数值,所以改用int8
	Path     string `yaml:"path,omitempty"`     // file path, for file appender, useless for console
}

type LogLevel

type LogLevel = zapcore.Level

type LogModule

type LogModule struct {
	File      *LogAppenderCfg  `yaml:"file,omitempty"`      // for file appender
	Console   *LogAppenderCfg  `yaml:"console,omitempty"`   // for console appender
	Appenders []LogAppenderCfg `yaml:"appenders,omitempty"` // other appenders
}

func GetDefLogCfg

func GetDefLogCfg(logFile string) *LogModule

func InitLogModuleCfg

func InitLogModuleCfg(baseCfg *LogModule, logModuleCfg *LogModule, moduleDefLogFile string) *LogModule

fill default data for log module, otherwise some value will be nil

func InitLogModuleCfgWithoutGlob

func InitLogModuleCfgWithoutGlob(logModuleCfg *LogModule, moduleDefLogFile string) *LogModule

type Meta

type Meta interface {
	Key() string
	Value() interface{}
	// contains filtered or unexported methods
}

Meta key-value

func NewMeta

func NewMeta(key string, value interface{}) Meta

NewMeta create meat

type Option

type Option func(*option)

Option custom setup config

func WithConsoleAppender

func WithConsoleAppender(appender LogAppender) Option

func WithConsoleDisable

func WithConsoleDisable(disabled bool) Option

WithConsoleDisable write log to os.Stdout or os.Stderr

func WithConsoleLevel

func WithConsoleLevel(level zapcore.Level) Option

func WithConsoleLevelInt8 added in v0.0.43

func WithConsoleLevelInt8(level int8) Option

func WithConsoleText

func WithConsoleText(text bool) Option

func WithDebugLevel

func WithDebugLevel() Option

WithDebugLevel only greater than 'level' will output

func WithErrorLevel

func WithErrorLevel() Option

WithErrorLevel only greater than 'level' will output

func WithField

func WithField(key, value string) Option

WithField add some field(s) to log

func WithFileP

func WithFileP(file string) Option

WithFileP write log to some file

func WithFileRotationP

func WithFileRotationP(file string) Option

WithFileRotationP write log to some file with rotation

func WithInfoLevel

func WithInfoLevel() Option

WithInfoLevel only greater than 'level' will output

func WithLevel

func WithLevel(level zapcore.Level) Option

WithLevel

func WithLevelInt8 added in v0.0.42

func WithLevelInt8(level int8) Option

WithLevelInt8

func WithNoCaller

func WithNoCaller(noCaller bool) Option

default is with caller

func WithText

func WithText(text bool) Option

default is json

func WithTimeLayout

func WithTimeLayout(timeLayout string) Option

WithTimeLayout custom time format

func WithWarnLevel

func WithWarnLevel() Option

WithWarnLevel only greater than 'level' will output

Jump to

Keyboard shortcuts

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