logx

package
v0.0.0-...-e56f5d9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatJson    = "json"
	FormatConsole = "console"
	FormatText    = "text"
)

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, fields ...zap.Field)

Debug logs a message at DebugLevel.

func Error

func Error(msg string, fields ...zap.Field)

Error logs a message at ErrorLevel.

func Fatal

func Fatal(msg string, fields ...zap.Field)

Fatal logs a message at FatalLevel.

func Info

func Info(msg string, fields ...zap.Field)

Info logs a message at InfoLevel.

func InitZapLogger

func InitZapLogger(config *Config, opts ...zap.Option) (*zapLogger, error)

func NewLogger

func NewLogger(configs ...configurer) (*zap.Logger, error)

func NewSugaredLogger

func NewSugaredLogger(configs ...configurer) (*zap.SugaredLogger, error)

func NewZapLogger

func NewZapLogger(configs ...configurer) (*zapLogger, error)

func Panic

func Panic(msg string, fields ...zap.Field)

Panic logs a message at PanicLevel.

func Warn

func Warn(msg string, fields ...zap.Field)

Warn logs a message at WarnLevel.

func WithConsole

func WithConsole() configurer

func WithDisableCaller

func WithDisableCaller() configurer

func WithDisableErrorVerbose

func WithDisableErrorVerbose() configurer

func WithDisableStacktrace

func WithDisableStacktrace() configurer

func WithDisableTimestamp

func WithDisableTimestamp() configurer

func WithFile

func WithFile(path, name string, maxSize, maxAge, maxBackups int, compress bool) configurer

func WithFormat

func WithFormat(format string) configurer

func WithLevel

func WithLevel(lvl Level) configurer

Types

type Config

type Config struct {
	Lvl                 Level       `toml:"level" json:"level"`
	OsStdout            bool        `toml:"os-stdout" json:"os-stdout"`
	File                *FileConfig `toml:"file" json:"file"`
	Format              string      `toml:"format" json:"format"`
	DisableTimestamp    bool        `toml:"disable-timestamp" json:"disable-timestamp"`
	Development         bool        `toml:"development" json:"development"`
	DisableCaller       bool        `toml:"disable-caller" json:"disable-caller"`
	DisableStacktrace   bool        `toml:"disable-stacktrace" json:"disable-stacktrace"`
	DisableErrorVerbose bool        `toml:"disable-error-verbose" json:"disable-error-verbose"`
}

Config represents log configurations in toml/json.

func NewDefaultConfig

func NewDefaultConfig() *Config

func (*Config) BuildZapEncoder

func (c *Config) BuildZapEncoder() zapcore.Encoder

func (*Config) BuildZapEncoderConfig

func (c *Config) BuildZapEncoderConfig() zapcore.EncoderConfig

func (*Config) BuildZapOptions

func (c *Config) BuildZapOptions() []zap.Option

func (*Config) BuildZapWriteSyncer

func (c *Config) BuildZapWriteSyncer() ([]zapcore.WriteSyncer, error)

type FileConfig

type FileConfig struct {
	Path string `toml:"path" json:"path"`
	Name string `toml:"name" json:"name"`

	// Along with lumberjack:
	// https://github.com/natefinch/lumberjack/blob/v2.0/lumberjack.go
	MaxSize    int  `toml:"maxsize" json:"maxsize"`
	MaxAge     int  `toml:"maxage" json:"maxage"`
	MaxBackups int  `toml:"maxbackups" json:"maxbackups"`
	Compress   bool `toml:"compress" json:"compress"`
}

FileConfig represents file to record log in toml/json.

func NewFileConfig

func NewFileConfig(path, name string, maxSize, maxAge, maxBackups int, compress bool) *FileConfig

func (*FileConfig) BuildLogger

func (f *FileConfig) BuildLogger() (*lumberjack.Logger, error)

type Level

type Level int
const (
	LvlFatal Level = iota
	LvlPanic
	LvlDPanic
	LvlError
	LvlWarn
	LvlInfo
	LvlDebug
)

Jump to

Keyboard shortcuts

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