log

package
v0.0.0-...-388d6c9 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package log provides the log config.go contains the log config

Package log provides the log

Index

Constants

View Source
const (
	// OutputConsole console output
	OutputConsole = "console"
	// OutputFile file output
	OutputFile = "file"

	// EncoderTypeConsole log format console encoder
	EncoderTypeConsole = "console"
	// EncoderTypeJSON log format json encoder
	EncoderTypeJSON = "json"
)
View Source
const DefaultLoggerName = "default"

DefaultLoggerName is the default logger name

Variables

View Source
var (
	// DefaultConfig default log config
	DefaultConfig = Config{
		Writers:    []string{OutputConsole},
		Format:     EncoderTypeConsole,
		Level:      "info",
		CallerSkip: 1,
	}
)
View Source
var Levels = map[string]zapcore.Level{
	"":      zapcore.DebugLevel,
	"debug": zapcore.DebugLevel,
	"info":  zapcore.InfoLevel,
	"warn":  zapcore.WarnLevel,
	"error": zapcore.ErrorLevel,
	"fatal": zapcore.FatalLevel,
}

Levels zapcore level

Functions

func Debug

func Debug(args ...any)

Debug logs to DEBUG log

func Debugf

func Debugf(format string, args ...any)

Debugf logs to DEBUG log, Arguments will be formatted with Sprint, Sprintf, or neither.

func Error

func Error(args ...any)

Error logs to ERROR log

func Errorf

func Errorf(format string, args ...any)

Errorf logs to ERROR log, Arguments will be formatted with Sprint, Sprintf, or neither.

func Fatal

func Fatal(args ...any)

Fatal logs to FATAL log

func Fatalf

func Fatalf(format string, args ...any)

Fatalf logs to FATAL log, Arguments will be formatted with Sprint, Sprintf, or neither.

func Info

func Info(args ...any)

Info logs to INFO log

func Infof

func Infof(format string, args ...any)

Infof logs to INFO log, Arguments will be formatted with Sprint, Sprintf, or neither.

func Panicf

func Panicf(format string, args ...any)

Panicf logs to PANIC log, Arguments will be formatted with Sprint, Sprintf, or neither.

func RegisterLogger

func RegisterLogger(loggerName string, c *Config, opts ...OptionFunc)

RegisterLogger register a logger with name

func Sync

func Sync()

Sync calls the zap defaultLogger's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func Warn

func Warn(args ...any)

Warn logs to WARN log

func Warnf

func Warnf(format string, args ...any)

Warnf logs to WARN log, Arguments will be formatted with Sprint, Sprintf, or neither.

Types

type Config

type Config struct {
	LogName string `json:"log_name" yaml:"log_name" mapstructure:"log_name"`
	// Writers log output(console, file)
	Writers []string `yaml:"writers" mapstructure:"writers" json:"writers"`
	// FileConfig log file config, if writers has file, must set file config
	FileConfig FileConfig `yaml:"file_config" mapstructure:"file_config" json:"file_config"`

	// Format log format type (console, json)
	Format string `yaml:"format" mapstructure:"format" json:"format"`

	// Level log level debug info error...
	Level string `yaml:"level" mapstructure:"level" json:"level"`

	// CallerSkip log caller skip
	CallerSkip int `yaml:"caller_skip" mapstructure:"caller_skip" json:"caller_skip"`
}

Config log config

type FileConfig

type FileConfig struct {
	// Filepath log file path
	Filepath string `yaml:"filepath" mapstructure:"filepath" json:"filepath"`
	// MaxAge log file max age, days
	MaxAge int `yaml:"max_age" mapstructure:"max_age" json:"max_age"`
	// MaxBackups max backup files
	MaxBackups int `yaml:"max_backups" mapstructure:"max_backups" json:"max_backups"`
	// Compress log file is compress
	Compress bool `yaml:"compress" mapstructure:"compress" json:"compress"`
	// MaxSize max file size, MB
	MaxSize int `yaml:"max_size" mapstructure:"max_size" json:"max_size"`
}

FileConfig log file config

type Logger

type Logger interface {
	// Debug logs to DEBUG log
	Debug(args ...any)
	// Info logs to INFO log
	Info(args ...any)
	// Warn logs to WARN log
	Warn(args ...any)
	// Error logs to ERROR log
	Error(args ...any)
	// Fatal logs to FATAL log
	Fatal(args ...any)
	// Debugln logs to DEBUG log
	Debugln(args ...any)
	// Infoln logs to INFO log
	Infoln(args ...any)
	// Warnln logs to WARN log
	Warnln(args ...any)
	// Errorln logs to ERROR log
	Errorln(args ...any)
	// Fatalln logs to FATAL log
	Fatalln(args ...any)
	// Debugf logs to DEBUG log, Arguments will be formatted with Sprint, Sprintf, or neither.
	Debugf(format string, args ...any)
	// Infof logs to INFO log, Arguments will be formatted with Sprint, Sprintf, or neither.
	Infof(format string, args ...any)
	// Warnf logs to WARN log, Arguments will be formatted with Sprint, Sprintf, or neither.
	Warnf(format string, args ...any)
	// Errorf logs to ERROR log, Arguments will be formatted with Sprint, Sprintf, or neither.
	Errorf(format string, args ...any)
	// Fatalf logs to FATAL log, Arguments will be formatted with Sprint, Sprintf, or neither.
	Fatalf(format string, args ...any)
	// Sync calls the zap defaultLogger's Sync method, flushing any buffered log entries.
	// Applications should take care to call Sync before exiting.
	Sync() error
	// WithFields set some business custom data to each log
	WithFields(fields ...any) Logger
}

Logger is the interface that wraps the basic log methods.

func GetLoggerByName

func GetLoggerByName(loggerName string) Logger

GetLoggerByName get logger by name

func WithFields

func WithFields(fields ...any) Logger

WithFields set some business custom data to each log

type OptionFunc

type OptionFunc func(config *Config)

OptionFunc is the option function for LogConfig

func WithCallerSkip

func WithCallerSkip(callerSkip int) OptionFunc

WithCallerSkip set caller skip

Directories

Path Synopsis
Package logger defines logging for components in the pudding project.
Package logger defines logging for components in the pudding project.

Jump to

Keyboard shortcuts

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