writer

package
v0.0.0-...-0a45852 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlushSize = 10240
	FlushTime = 500 * time.Millisecond
)
View Source
const (
	BufferSize = 10240
)

Variables

This section is empty.

Functions

func NewBufferedRotateFileWriter

func NewBufferedRotateFileWriter(f *BufferedRotateFile, config ...Config) io.WriteCloser

func NewRotateFileWriter

func NewRotateFileWriter(f *RotateFile, conf ...Config) io.WriteCloser

func ZipLogs

func ZipLogs(dir string, name string, files ...string) error

func ZipLogsAsync

func ZipLogsAsync(dir string, name string, files ...string) error

Types

type AsyncBufferLogWriter

type AsyncBufferLogWriter struct {
	FlushSize int64
	// contains filtered or unexported fields
}

func NewAsyncBufferWriter

func NewAsyncBufferWriter(w io.Writer, closer Closer, c ...Config) *AsyncBufferLogWriter

带Buffer的Writer,本身Write、Close方法线程安全,参数WriteCloser可以非线程安全 Param: w - 实际写入的Writer, c - Writer的配置,如果不传入则使用默认值,否则使用第1个配置。

func (*AsyncBufferLogWriter) Close

func (w *AsyncBufferLogWriter) Close() error

func (*AsyncBufferLogWriter) Flush

func (w *AsyncBufferLogWriter) Flush() error

func (*AsyncBufferLogWriter) Write

func (w *AsyncBufferLogWriter) Write(data []byte) (n int, err error)

type AsyncLogWriter

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

func NewAsyncWriter

func NewAsyncWriter(w io.Writer, closer Closer, bufSize int, block bool) *AsyncLogWriter

异步写的Writer,本身Write、Close方法线程安全,参数WriteCloser可以非线程安全 Param: w - 实际写入的Writer, bufSize - 接收的最大长度, block - 如果为true,则当超出bufSize大小时Write方法阻塞,否则返回error

func (*AsyncLogWriter) Close

func (w *AsyncLogWriter) Close() error

func (*AsyncLogWriter) Write

func (w *AsyncLogWriter) Write(data []byte) (n int, err error)

type BufferedRotateFile

type BufferedRotateFile struct {
	//文件路径
	Path string
	// 文件的大小阈值
	MaxFileSize int64
	// 滚动频率
	RotateFrequency RotateFrequency
	// 滚动文件处理
	RotateFunc func(dir string, name string, files ...string) error
	// contains filtered or unexported fields
}

func (*BufferedRotateFile) Close

func (f *BufferedRotateFile) Close() error

func (*BufferedRotateFile) Open

func (f *BufferedRotateFile) Open(conf Config) error

func (*BufferedRotateFile) Write

func (f *BufferedRotateFile) Write(data []byte) (int, error)

type Closer

type Closer func() error

type Config

type Config struct {
	// 触发刷新的数据大小阈值
	FlushSize int64

	// 异步缓存的大小,如果超出可能会阻塞或返回错误(由Block控制)
	BufferSize int

	// 触发刷新的时间间隔
	FlushInterval time.Duration

	// 如果为true,则当超出bufSize大小时Write方法阻塞,否则返回error
	Block bool
}

type LockedWriteCloser

type LockedWriteCloser struct {
	W io.WriteCloser
	// contains filtered or unexported fields
}

func (*LockedWriteCloser) Close

func (lw *LockedWriteCloser) Close() error

func (*LockedWriteCloser) Write

func (lw *LockedWriteCloser) Write(d []byte) (int, error)

type LockedWriter

type LockedWriter struct {
	W io.Writer
	// contains filtered or unexported fields
}

Logging不会自动为输出的Writer加锁,如果需要加锁请使用这个封装工具: logging.SetOutPut(&writer.LockedWriter{w})

func (*LockedWriter) Write

func (lw *LockedWriter) Write(d []byte) (int, error)

type RotateFile

type RotateFile struct {
	//文件路径
	Path string
	// 文件的大小阈值
	MaxFileSize int64
	// 滚动频率
	RotateFrequency RotateFrequency
	// 滚动文件处理
	RotateFunc func(dir string, name string, files ...string) error
	// contains filtered or unexported fields
}

func (*RotateFile) Close

func (f *RotateFile) Close() error

func (*RotateFile) Open

func (f *RotateFile) Open() error

func (*RotateFile) Write

func (f *RotateFile) Write(data []byte) (int, error)

type RotateFrequency

type RotateFrequency = time.Duration
const (
	// 仅使用一个文件记录日志
	RotateNone RotateFrequency = 0
	// 每天凌晨滚动文件
	RotateEveryDay RotateFrequency = time.Hour * 24
	// 每小时整点时滚动文件
	RotateEveryHour RotateFrequency = time.Hour
	// WARNING: for test only!
	RotateEveryMinute RotateFrequency = time.Minute
	RotateEverySecond RotateFrequency = time.Second
)

Jump to

Keyboard shortcuts

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