rollwriter

package
v0.0.0-...-115e584 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

该组件可以与任何可以写入io.Writer的日志包进行配合(包括标准库的log包) 主要特性: 1. 支持日志按文件大小进行滚动 2. 支持日志按时间进行滚动 3. 支持自动清理过期或者多余的日志文件 4. 支持压缩日志文件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncOption

type AsyncOption func(*AsyncOptions)

func WithDropLog

func WithDropLog(b bool) AsyncOption

func WithLogQueueSize

func WithLogQueueSize(n int) AsyncOption

func WithWriteLogInterval

func WithWriteLogInterval(n int) AsyncOption

func WithWriteLogSize

func WithWriteLogSize(n int) AsyncOption

type AsyncOptions

type AsyncOptions struct {
	// LogQueueSize 日志异步队列大小
	LogQueueSize int
	// WriteLogSize 触发日志异步写入的大小阈值
	WriteLogSize int
	// WriteLogInterval 触发日志异步写入的时间间隔阈值
	WriteLogInterval int
	// DropLog 是否丢弃日志(当日志异步队列写满时)
	DropLog bool
}

type AsyncRollWriter

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

func NewAsyncRollWriter

func NewAsyncRollWriter(logger io.Writer, opt ...AsyncOption) *AsyncRollWriter

NewAsyncRollWriter 根据传入的参数创建一个RollWriter对

func (*AsyncRollWriter) Close

func (w *AsyncRollWriter) Close() error

func (*AsyncRollWriter) Sync

func (w *AsyncRollWriter) Sync() error

func (*AsyncRollWriter) Write

func (w *AsyncRollWriter) Write(data []byte) (int, error)

type Option

type Option func(*Options)

Option 调用参数工具函数

func WithCompress

func WithCompress(b bool) Option

func WithMaxAge

func WithMaxAge(n int) Option

WithMaxAge 设置日志最大保留时间(天)

func WithMaxBackups

func WithMaxBackups(n int) Option

WithMaxBackups 设置日志保留的最大文件数

func WithMaxSize

func WithMaxSize(n int) Option

WithMaxSize 设置日志文件最大大小(MB)

func WithRotationTime

func WithRotationTime(s string) Option

type Options

type Options struct {
	// MaxSize 日志文件最大大小(字节)
	MaxSize int64
	// MaxBackups 保留的日志最大文件数
	MaxBackups int
	// MaxAge 日志最大保留时间(天)
	MaxAge int
	// 日志文件是否压缩
	Compress bool
	// TimeFormat 按时间分隔文件的时间格式
	TimeFormat string
}

Option RollWriter类调用参数

type RollWriter

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

func NewRollWriter

func NewRollWriter(filePath string, opt ...Option) (*RollWriter, error)

func (*RollWriter) Close

func (w *RollWriter) Close() error

func (*RollWriter) Write

func (w *RollWriter) Write(v []byte) (n int, err error)

Jump to

Keyboard shortcuts

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