writer

package
v0.19.0 Latest Latest
Warning

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

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

Documentation

Overview

Package writer provides some log writers.

Index

Constants

This section is empty.

Variables

View Source
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 Close

func Close(writer io.Writer) (err error)

Close closes the writer if it has implemented the interface io.Closer.

func Flush added in v0.18.0

func Flush(writer io.Writer) (err error)

Flush flushes the writer if it has implemented the interface Flusher.

func ParseSize

func ParseSize(s string) (size int64, err error)

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.

func UnwrapWriter

func UnwrapWriter(writer io.Writer) io.Writer

UnwrapWriter recursively unwraps the wrapped innest writer from the given writer if it has implemented the interface WrappedWriter. Or return the original writer.

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

type LevelWriter interface {
	WriteLevel(level int, data []byte) (n int, err error)
	io.Writer
}

LevelWriter is a writer with the level.

func LevelSplitWriter added in v0.11.0

func LevelSplitWriter(defaultWriter io.Writer, levelWriters map[int]io.Writer) LevelWriter

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.

func (*SizedRotatingFile) Write

func (f *SizedRotatingFile) Write(data []byte) (n int, err error)

Write implements io.Writer.

type WrappedWriter

type WrappedWriter interface {
	UnwrapWriter() io.Writer
	io.Writer
}

WrappedWriter is a writer which wraps and returns the inner writer.

Jump to

Keyboard shortcuts

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