logging

package
v0.0.0-...-48595db Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WhenMinutely 分钟级
	WhenMinutely = 1
	// WhenHourly 小时级
	WhenHourly = 2
	// WhenDaily 天级
	WhenDaily = 3
)

Variables

View Source
var (
	// LogFileNameDailyFormat 天级文件名模式
	LogFileNameDailyFormat = "2006-01-02"
	// LogFileNameHourlyFormat 小时级文件名模式
	LogFileNameHourlyFormat = "2006-01-02T15"
	// LogFileNameMinutelyFormat 分钟级文件名模式
	LogFileNameMinutelyFormat = "2006-01-02T15:04"
)
View Source
var (
	// LogCallDepth 打印调用深度
	LogCallDepth = 2
)

Functions

func CallerInfo

func CallerInfo(skip int) (string, string, int)

CallerInfo 获取运行时位置

return:
	0: function name
	1: file
	2: line no

func NewFDailyLogger

func NewFDailyLogger(path string, prefix string, flag int) (*log.Logger, io.Closer, error)

NewFDailyLogger 天切片日志

func NewFHourlyLogger

func NewFHourlyLogger(path string, prefix string, flag int) (*log.Logger, io.Closer, error)

NewFHourlyLogger 小时切片日志

func NewSFDailyLogger

func NewSFDailyLogger(path string, level slog.Level) (*slog.Logger, io.Closer, error)

NewSFDailyLogger 天切片结构化日志

func NewSFHourlyLogger

func NewSFHourlyLogger(path string, level slog.Level) (*slog.Logger, io.Closer, error)

NewSFHourlyLogger 小时切片结构化日志

func Shortpath

func Shortpath(p string, n uint) string

Shortpath returns the last n elements of the path p.

func SimpleFLogger

func SimpleFLogger(path string, prefix string, flag int) (*log.Logger, *os.File, error)

SimpleFLogger ...

func SimpleLogger

func SimpleLogger(path string, prefix string) (*log.Logger, *os.File, error)

SimpleLogger 便捷方法

func Std

func Std(prefix string) *log.Logger

Std 创建一个打在标准输出的日志

Types

type TimedRotatingFile

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

TimedRotatingFile implement io.Writer

时间切分文件, 不能多进程使用
log.Logger模块在Output()时本身会加锁,因此这里没有额外加锁

func NewDailyRotatingFile

func NewDailyRotatingFile(path string) (*TimedRotatingFile, error)

NewDailyRotatingFile 创建按天切分的文件

func NewHourlyRotatingFile

func NewHourlyRotatingFile(path string) (*TimedRotatingFile, error)

NewHourlyRotatingFile 创建按小时切分的文件

func NewTimedRotatingFile

func NewTimedRotatingFile(path string, when int, format string) (*TimedRotatingFile, error)

NewTimedRotatingFile 创建时间切分的文件

func (*TimedRotatingFile) Close

func (trf *TimedRotatingFile) Close() error

Close 关闭文件

func (*TimedRotatingFile) Write

func (trf *TimedRotatingFile) Write(buf []byte) (int, error)

Write 文件写入

Jump to

Keyboard shortcuts

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