kratos: Index | Files

package filewriter

import ""


Package Files

filewriter.go option.go


const (
    RotateDaily = "2006-01-02"


type FileWriter Uses

type FileWriter struct {
    // contains filtered or unexported fields

FileWriter create file log writer

func New Uses

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

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

func (*FileWriter) Close Uses

func (f *FileWriter) Close() error

Close close file writer

func (*FileWriter) Write Uses

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 Uses

type Option func(opt *option)

Option filewriter option

func ChanSize Uses

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 Uses

func MaxFile(n int) Option

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

func MaxSize Uses

func MaxSize(n int64) Option

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

func RotateFormat Uses

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 filewriter imports 13 packages (graph) and is imported by 2 packages. Updated 2020-03-29. Refresh now. Tools for package owners.