logger

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RollNon 日志文件不轮转
	RollNon int = 0

	// RollBySize 按大小轮转
	RollBySize int = 1

	// RollByTime 按时间轮转
	RollByTime int = 2
)

Variables

View Source
var (
	// TRACE 记录所有日志
	TRACE *log.Logger

	// INFO 记录重要信息日志
	INFO *log.Logger

	// DEBUG 记录调试信息日志
	DEBUG *log.Logger

	// ERROR 记录错误信息日志
	ERROR *log.Logger
)

Functions

func CreateLog added in v1.0.1

func CreateLog() error

CreateLog 创建日志记录

func NewGwriterWithStdout added in v1.0.4

func NewGwriterWithStdout(c *Conf) (io.Writer, error)

NewGwriterWithStdout 创建带控制台输出的 MultiWriter

Types

type Conf added in v1.0.1

type Conf struct {

	// 文件路径 如: C:\\log
	FilePath string `json:"filePath"`

	// 命名日期时间格式:yyyyMMddHHmmss
	TimePatten string

	// 文件名 如:system.log
	FileName string `json:"fileName"`

	// 保留天数,超过后自动清除
	RemainDay int `json:"remainDay"`

	// 文件滚动策略,按大小,按时间等等
	// RollPolicy 策略支持 RollNon, RollBySize, RollByTime
	// RollTime 滚动的时间间隔,单位秒
	// RollSize 滚动的文件大小,单位Byte
	RollPolicy int   `json:"rollPolicy"`
	RollTime   int64 `json:"rollTime"`
	RollSize   int64 `json:"rollSize"`

	// 是否压缩
	Compress bool `json:"compress"`
}

Conf 是 Gwriter 的配置文件

func DefaultConf added in v1.0.1

func DefaultConf() *Conf

DefaultConf 创建默认GLog配置

type GWriter added in v1.0.1

type GWriter struct {

	// 写操作同步锁
	sync.Mutex
	// contains filtered or unexported fields
}

GWriter 是一个线程安全的文件写入对象,它实现了IGWriter接口

func (*GWriter) Close added in v1.0.1

func (w *GWriter) Close() error

Close GWriter 实现 IGWriter 中的 Close 接口

func (*GWriter) CompressFile added in v1.0.1

func (w *GWriter) CompressFile(srcFile string) error

CompressFile 文件gz压缩

func (*GWriter) Rolling added in v1.0.1

func (w *GWriter) Rolling() error

Rolling 轮换文件

func (*GWriter) Write added in v1.0.1

func (w *GWriter) Write(b []byte) (n int, err error)

Write GWriter 实现 IGWriter 中的 io.Writer 接口

type IGWriter added in v1.0.1

type IGWriter interface {
	io.Writer
	Close() error
}

IGWriter 实现了 io.writer,可以将其传入任何框架以支持日志文件记录

func NewGwriter added in v1.0.1

func NewGwriter(c *Conf) (IGWriter, error)

NewGwriter 创建 Gwriter

Jump to

Keyboard shortcuts

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