Documentation
¶
Overview ¶
Package writer provides some log writers.
Index ¶
- Variables
- func BufferWriter(writer io.Writer, bufSize int) io.WriteCloser
- func Close(writer io.Writer) (err error)
- func Flush(writer io.Writer) (err error)
- func ParseSize(s string) (size int64, err error)
- func SafeWriter(writer io.Writer) io.WriteCloser
- func UnwrapWriter(writer io.Writer) io.Writer
- type Flusher
- type LevelWriter
- type SizedRotatingFile
- type WrappedWriter
Constants ¶
This section is empty.
Variables ¶
var Discard io.Writer
Discard is the writer to discard all the written data.
For Go1.16+, it is equal to io.Discard. Or, it's an internal implementation.
Functions ¶
func BufferWriter ¶ added in v0.9.0
func BufferWriter(writer io.Writer, bufSize int) io.WriteCloser
BufferWriter returns a buffer writer, which implements the interfaces Flusher and WrappedWriter, writes the data into the buffer and flushes all the datas into the wrapped writer when the buffer is full.
If bufSize is equal to or less than 0, it is 4096 by default.
func ParseSize ¶
ParseSize parses the size string. The size maybe have a unit suffix, such as "123", "123M, 123G". Valid size units are "b", "B", "k", "K", "m", "M", "g", "G", "t", "T", "p", "P", "e", "E". The lower units are 1000x, and the upper units are 1024x.
Notice: "" will be considered as 0.
func SafeWriter ¶
func SafeWriter(writer io.Writer) io.WriteCloser
SafeWriter is guaranteed that only a single writing operation can proceed at a time, which implements the interface LevelWriter, WrappedWriter and Flusher.
It's necessary for thread-safe concurrent writes.
Types ¶
type Flusher ¶ added in v0.18.0
type Flusher interface {
Flush() error
}
Flusher is used to flush the data in the writer to the underlying storage media.
type LevelWriter ¶ added in v0.11.0
LevelWriter is a writer with the level.
func LevelSplitWriter ¶ added in v0.11.0
LevelSplitWriter returns a writer to write the log into the different writer by the level.
func ToLevelWriter ¶ added in v0.11.0
func ToLevelWriter(writer io.Writer) LevelWriter
ToLevelWriter converts the io.Writer to LevelWriter, which implements the interface WrappedWriter, Flusher and io.Closer.
type SizedRotatingFile ¶
type SizedRotatingFile struct {
// contains filtered or unexported fields
}
SizedRotatingFile is a file rotating logging writer based on the size.
func NewSizedRotatingFile ¶
func NewSizedRotatingFile(filename string, filesize, filenum int, fileperm ...os.FileMode) *SizedRotatingFile
NewSizedRotatingFile returns a new SizedRotatingFile, which is not thread-safe.
Default:
fileperm: 0644 filesize: 100 * 1024 * 1024 filenum: 0
func (*SizedRotatingFile) Close ¶
func (f *SizedRotatingFile) Close() (err error)
Close implements io.Closer.
func (*SizedRotatingFile) Flush ¶
func (f *SizedRotatingFile) Flush() (err error)
Flush flushes the data to the underlying disk.