Back to godoc.org

Package filewriter

v0.3.3
Latest Go to latest

The latest major version is .

Published: Jan 20, 2020 | Licenses: MIT , MIT | Module: github.com/bilibili/kratos

Index

Constants

const (
	RotateDaily = "2006-01-02"
)

RotateFormat

type FileWriter

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

FileWriter create file log writer

func New

func New(fpath string, fns ...Option) (*FileWriter, error)

New FileWriter A FileWriter is safe for use by multiple goroutines simultaneously.

func (*FileWriter) Close

func (f *FileWriter) Close() error

Close close file writer

func (*FileWriter) Write

func (f *FileWriter) Write(p []byte) (int, error)

Write write data to log file, return write bytes is pseudo just for implement io.Writer.

type Option

type Option func(opt *option)

Option filewriter option

func ChanSize

func ChanSize(n int) Option

ChanSize set internal chan size default 8192 use about 64k memory on x64 platfrom static, because filewriter has internal object pool, change chan size bigger may cause filewriter use a lot of memory, because sync.Pool can't set expire time memory won't free until program exit.

func MaxFile

func MaxFile(n int) Option

MaxFile default 999, 0 meaning unlimit. TODO: don't create file list if MaxSize is unlimt.

func MaxSize

func MaxSize(n int64) Option

MaxSize set max size for single log file, defult 1GB, 0 meaning unlimit.

func RotateFormat

func RotateFormat(format string) Option

RotateFormat e.g 2006-01-02 meaning rotate log file every day. NOTE: format can't contain ".", "." will cause panic ヽ(*。>Д<)o゜.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier