log

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerTagKey = "ServerTag"
	PathKey      = "path"
	AccIDKey     = "accID"
	ECodeKey     = "eCode"
	TokenKey     = "token"
	RealIPKey    = "realIP"
)
View Source
const (
	DefaultMaxSize         = 1024
	DefaultMaxAge          = 7
	DefaultMaxBackups      = 30
	DefaultCompress        = false
	DefaultOutStd          = false
	DefaultTimestampFormat = "2006-01-02 15:04:05.000"
	DefaultLevel           = zapcore.InfoLevel

	// rotatelogs 默认参数
	RotateDefaultRotationSize  = 1 * 1024 * 1024 * 1024 // 1G
	RotateDefaultRotationTime  = 1 * time.Hour
	RotateDefaultMaxAge        = 0 // if both DefaultMaxAge and DefaultRotationCount are 0, give maxAge a sane default "7 * 24 * time.Hour"
	RotateDefaultRotationCount = 0 // 0 means this option is disabled.
)

Variables

This section is empty.

Functions

func DebugF

func DebugF(format string, v ...interface{})

func ErrorF

func ErrorF(format string, v ...interface{})

func ExportSLog

func ExportSLog(log *zap.Logger, tag string)

func GetLogFields

func GetLogFields() []logField

func InfoF

func InfoF(format string, v ...interface{})

func NewLogger

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

func NewRotation

func NewRotation(options *Options) (io.Writer, error)

func PanicF

func PanicF(format string, v ...interface{})

func RegisterLogField

func RegisterLogField(k string, v LogFieldType)

func SetSLog

func SetSLog(l *ServerLog)

func Sync

func Sync()

func SystemDebug

func SystemDebug(code LogECode, id LogAccID, path LogPath, token LogToken, ip LogRealIP, format string, v ...interface{})

func SystemError

func SystemError(code LogECode, id LogAccID, path LogPath, token LogToken, ip LogRealIP, format string, v ...interface{})

func SystemInfo

func SystemInfo(code LogECode, id LogAccID, path LogPath, token LogToken, ip LogRealIP, format string, v ...interface{})

func SystemReqInfo

func SystemReqInfo(id LogAccID, path LogPath, token LogToken, ip LogRealIP, format string, v ...interface{})

func SystemWarn

func SystemWarn(code LogECode, id LogAccID, path LogPath, token LogToken, ip LogRealIP, format string, v ...interface{})

func WarnF

func WarnF(format string, v ...interface{})

Types

type BaseFlow

type BaseFlow struct {
	*CommonFlow
	BaseFields []zap.Field
}

func (*BaseFlow) SetCommon

func (f *BaseFlow) SetCommon(cf *CommonFlow)

func (*BaseFlow) TaDataFields

func (f *BaseFlow) TaDataFields(fieldKey string, isSubObject func(k string) bool) []zap.Field

func (*BaseFlow) ZapFields

func (f *BaseFlow) ZapFields() []zap.Field

type CommonFlow

type CommonFlow struct {
	Fields []zap.Field
}

基础属性字段,每条行为日志都打印相关信息

type Helper

type Helper interface {
	SystemReqInfo(id LogAccID, path LogPath, token LogToken, ip LogRealIP, format string, v ...interface{})
	SystemLog(level zapcore.Level, code LogECode, id LogAccID, path LogPath, token LogToken, ip LogRealIP, format string, v ...interface{})
	Log(level zapcore.Level, format string, v ...interface{})
	Sync()
}

func NewHelper

func NewHelper(logger *zap.Logger, tag string) Helper

type LogAccID

type LogAccID string

type LogECode

type LogECode int32

type LogField

type LogField interface {
	GetField() zap.Field
	GetKey() string
	GetType() string
}

type LogFieldType

type LogFieldType = string
var LogFieldTypeBool LogFieldType = "bool"
var LogFieldTypeDate LogFieldType = "date"
var LogFieldTypeFloat64 LogFieldType = "float64"
var LogFieldTypeInt LogFieldType = "int32"
var LogFieldTypeInt64 LogFieldType = "int64"
var LogFieldTypeString LogFieldType = "string"
var LogFieldTypeUint LogFieldType = "uint32"
var LogFieldTypeUint64 LogFieldType = "uint64"

type LogPath

type LogPath string

type LogRealIP

type LogRealIP string

type LogToken

type LogToken string

type Option

type Option func(*Options) error

func WithCaller

func WithCaller(c bool) Option

func WithCallerFunc

func WithCallerFunc(c bool) Option

func WithCallerSkip

func WithCallerSkip(c int) Option

func WithCompress

func WithCompress(c bool) Option

func WithEncoderConf

func WithEncoderConf(e *zapcore.EncoderConfig) Option

func WithGlobPattern

func WithGlobPattern(g string) Option

WithGlobPattern 日志滚动

func WithLevel

func WithLevel(l zapcore.Level) Option

func WithLinkName

func WithLinkName(l string) Option

func WithMaxAge

func WithMaxAge(a time.Duration) Option

func WithMaxBackups

func WithMaxBackups(b int) Option

func WithMaxSize

func WithMaxSize(s int) Option

func WithOutStd

func WithOutStd(s bool) Option

func WithRotationCount

func WithRotationCount(c uint) Option

func WithRotationSize

func WithRotationSize(s int64) Option

func WithRotationTime

func WithRotationTime(t time.Duration) Option

func WithSuffix

func WithSuffix(s string) Option

type Options

type Options struct {
	Suffix      string                 // 日志文件后缀
	MaxSize     int                    // 每个日志文件保存的最大尺寸 单位:M
	MaxAge      int                    // 文件最多保存多少天
	MaxBackups  int                    // 日志文件最多保存多少个备份
	Compress    bool                   // 是否压缩
	OutStd      bool                   // 是否输出到控制台
	EncoderConf *zapcore.EncoderConfig // zap日志编码
	Level       zapcore.Level          // 日志等级
	Caller      bool                   // 是否打印行号,函数
	CallerFunc  bool                   // 是否打印函数
	CallerSkip  int                    // Caller skip frame count for caller info

	// rotatelogs使用参数
	// log filename pattern, if GlobPattern is empty, log will not be written to file
	GlobPattern string
	// sets the symbolic link name that gets linked to the current file name being used.
	LinkName string
	// (bytes) the log file size between rotation
	RotationSize int64
	// the time between rotation
	RotationTime time.Duration
	// the max age of a log file before it gets purged from the file system.
	// if both RotationCount and MaxAge are 0, give maxAge a sane default "7 * 24 * time.Hour"
	LogMaxAge time.Duration
	// the number of files should be kept before it gets purged from the file system
	// if both RotationCount and MaxAge are 0, give maxAge a sane default "7 * 24 * time.Hour"
	RotationCount uint
}

func NewOptions

func NewOptions(opts ...Option) (*Options, error)

type ServerLog

type ServerLog struct {
	Helper
}

func NewServerLogger

func NewServerLogger(tag string, opts ...Option) (*ServerLog, error)

options中GlobPattern不为空使用rotatelogs轮转 同时存在使用rotatelogs轮转

Jump to

Keyboard shortcuts

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