zlog

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	M10  = 1024 * 1024 * 10
	M20  = 2 * M10
	M50  = 5 * M10
	M100 = 2 * M50
)
View Source
const (
	Hour   = time.Hour
	Hour6  = 6 * Hour
	Hour12 = 2 * Hour6
	Hour24 = 2 * Hour12
)
View Source
const (
	FmtStandard  = log.Llongfile | log.Ldate | log.Lmicroseconds
	FileStandard = os.O_WRONLY | os.O_CREATE | os.O_APPEND
)

Variables

View Source
var (
	LogLevelMap = map[LogLevel]string{
		DEBUG: "DEBUG",
		INFO:  "INFO",
		WARN:  "WARN",
		ERROR: "ERROR",
		FATAL: "FATAL",
	}
)

Functions

func CleanHisLog

func CleanHisLog(filePath string, keepCnt int)

func Close

func Close() error

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func InitZlog

func InitZlog(logFilePath string, logLevel LogLevel, modelLevel ModelLevel, option ...LogFileManageOption)

func Rename

func Rename(filePath string) (err error)

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func WithContext added in v0.1.4

func WithContext(ctx context.Context) (spanId, traceId string)

Types

type DateFileManage

type DateFileManage struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDateCutMode

func NewDateCutMode(filePath string, options ...FileManageOptions) *DateFileManage

NewDateCutMode 创建文件日期管理器, 默认1天1切

func (*DateFileManage) Close

func (d *DateFileManage) Close() error

func (*DateFileManage) FilePath

func (d *DateFileManage) FilePath() string

func (*DateFileManage) GetFile

func (d *DateFileManage) GetFile() *os.File

func (*DateFileManage) IsCut

func (d *DateFileManage) IsCut(f SetOutput) error

type DateOption

type DateOption func(*DateFileManage)

type FileManageOption

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

type FileManageOptions

type FileManageOptions func(*FileManageOption)

func WithCutIntervalDay

func WithCutIntervalDay(cutIntervalDay int) FileManageOptions

func WithCutIntervalTime

func WithCutIntervalTime(cutInterval time.Duration) FileManageOptions

func WithCutSize

func WithCutSize(cutSize int64) FileManageOptions

func WithKeepCnt

func WithKeepCnt(keepCnt int) FileManageOptions

type LogFileManage

type LogFileManage interface {
	IsCut(SetOutput) error // 是否切割文件
	GetFile() *os.File     // 获取文件操作对象
	FilePath() string      // 文件名
	Close() error          // 关闭文件
}

type LogFileManageOption

type LogFileManageOption func(*Option)

func WithLogFileManage

func WithLogFileManage(logFileManage LogFileManage) LogFileManageOption

type LogLevel

type LogLevel int8
const (
	DEBUG LogLevel = 1 << iota
	INFO
	WARN
	ERROR
	FATAL
	ALLLogLevel = DEBUG | INFO | WARN | ERROR
)

type ModelLevel

type ModelLevel int8
const (
	OnlyStd ModelLevel = iota
	OnlyFile
	AllModelLevel
)

type Option

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

type SetOutput

type SetOutput func(io.Writer)

type SizeFileManage

type SizeFileManage struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSizeCutMode

func NewSizeCutMode(filePath string, options ...FileManageOptions) *SizeFileManage

NewSizeCutMode 创建文件大小管理器, 默认20M切割

func (*SizeFileManage) Close

func (s *SizeFileManage) Close() error

func (*SizeFileManage) FilePath

func (s *SizeFileManage) FilePath() string

func (*SizeFileManage) GetFile

func (s *SizeFileManage) GetFile() *os.File

func (*SizeFileManage) IsCut

func (s *SizeFileManage) IsCut(f SetOutput) error

type SizeOption

type SizeOption func(*SizeFileManage)

type TimeFileManage

type TimeFileManage struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTimeFileManage

func NewTimeFileManage(filePath string, options ...FileManageOptions) *TimeFileManage

NewTimeFileManage 创建文件大小管理器, 默认20M切割

func (*TimeFileManage) Close

func (t *TimeFileManage) Close() error

func (*TimeFileManage) FilePath

func (t *TimeFileManage) FilePath() string

func (*TimeFileManage) GetFile

func (t *TimeFileManage) GetFile() *os.File

func (*TimeFileManage) IsCut

func (t *TimeFileManage) IsCut(f SetOutput) error

type TimeOption

type TimeOption func(*TimeFileManage)

Jump to

Keyboard shortcuts

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