zaplogger

package module
v0.0.0-...-1bb6c05 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEVELOPMENT = 0
	PRODUCTION  = 1
)

Variables

This section is empty.

Functions

func ConsoleSyncer

func ConsoleSyncer() zapcore.WriteSyncer

控制台同步

func FileSyncer

func FileSyncer(conf *Config) zapcore.WriteSyncer

文件同步

func GenEncoderConfig

func GenEncoderConfig(conf *Config) zapcore.EncoderConfig

func NewZapLogger

func NewZapLogger(options ...Options) *zap.Logger

Types

type Config

type Config struct {
	// Filename is the file to write logs to.  Backup log files will be retained
	// in the same directory.  It uses <processname>-lumberjack.log in
	// os.TempDir() if empty.
	Filename string `json:"filename" yaml:"filename"`

	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int `json:"maxsize" yaml:"maxsize"`

	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	MaxAge int `json:"maxage" yaml:"maxage"`

	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int `json:"maxbackups" yaml:"maxbackups"`

	// LocalTime determines if the time used for formatting the timestamps in
	// backup files is the computer's local time.  The default is to use UTC
	// time.
	LocalTime bool `json:"localtime" yaml:"localtime"`

	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool `json:"compress" yaml:"compress"`

	//development or production.The default is DEVELOPMENT
	ENV int8 `json:"env"`
	// contains filtered or unexported fields
}

type Options

type Options func(o *Config)

func WithMaxAge

func WithMaxAge(maxFileSize int) Options

日志文件保最大留时长分(天),默认不移除

func WithProduction

func WithProduction() Options

生产模式,只输出到日志文件

func WithRotatedMaxSize

func WithRotatedMaxSize(maxFileSize int) Options

日志文件大小分割界限(M),默认100Mb

func WithSyncFile

func WithSyncFile(file string) Options

同步日志文件

func WithTimeLayout

func WithTimeLayout(layout string) Options

日志文件保最大留时长分(天),默认不移除

Jump to

Keyboard shortcuts

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