Documentation ¶
Index ¶
- func Close(closers ...io.Closer) error
- func CloseSingle(closer io.Closer) error
- func CountLines(r io.Reader) (int, error)
- func CountLines1(r io.Reader) (int, error)
- func MultiReader(readers ...io.Reader) io.Reader
- func MultiWriteCloser(writeClosers ...io.WriteCloser) io.WriteCloser
- func MultiWriter(writers ...io.Writer) io.Writer
- func NewDailyWriteCloser(filePath string, options ...LumberjackOption) (io.WriteCloser, error)
- func NewFileReader(filePath string) (*os.File, error)
- func NewReadWriter(s []byte) *bytes.Buffer
- func NewReadWriterFromString(str string) *bytes.Buffer
- func NewReader(s []byte) io.Reader
- func NewReaderFromString(str string) io.Reader
- func NewRotatableWriteCloser(filePath string, maxSize int64, options ...LumberjackOption) (*lumberjack.Roller, error)
- func NewRotatableWriteCloserWithSpec(filePath string, spec string, options ...LumberjackOption) (io.WriteCloser, error)
- func NopCloserToReadSeeker(readSeeker io.ReadSeeker) io.ReadSeekCloser
- func NopCloserToReader(reader io.Reader) io.ReadCloser
- func NopCloserToWriter(writer io.Writer) io.WriteCloser
- func ReadFromReader(reader io.Reader) ([]byte, error)
- func ToBufioReader(reader io.Reader) *bufio.Reader
- func TryToClose(objs ...any) error
- type DailyWriteCloser
- type LumberjackOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Close ¶ added in v2.1.7
Close
PS: 就算循环过程中返回了非nil的error,也要继续向下循环(尽可能多地关闭).
@param closers (1) 可以为nil(即不传参);(2) 其中可以有nil @return 发生error的话,返回第一个
func CloseSingle ¶ added in v2.1.7
func MultiWriteCloser ¶
func MultiWriteCloser(writeClosers ...io.WriteCloser) io.WriteCloser
MultiWriteCloser
PS: 参考了 io.MultiWriter().
func NewDailyWriteCloser ¶ added in v2.1.9
func NewDailyWriteCloser(filePath string, options ...LumberjackOption) (io.WriteCloser, error)
NewDailyWriteCloser 每天凌晨0点,执行Rotate().
@param options 可选配置,参考 NewRotatableWriteCloser()
func NewFileReader ¶
NewFileReader
!!!:要在外部手动调用 *os.File 的Close方法.
@return os.File 结构体 实现了 io.Reader 接口
func NewReaderFromString ¶
func NewRotatableWriteCloser ¶ added in v2.1.9
func NewRotatableWriteCloser(filePath string, maxSize int64, options ...LumberjackOption) (*lumberjack.Roller, error)
NewRotatableWriteCloser 可rotate(依据传参maxSize)的io.WriteCloser.
PS: (1) 如果 当前目标文件 被人为删了,会丢失部分输出直至再次调用Rotate(). (2) 可以同时配置 MaxBackups 和 MaxAge.
@param maxSize unit: byte @param options 可选配置: WithCompress() [默认: 不压缩] 是否压缩被rotate的文件? WithMaxBackups() [默认: 保留所有旧日志] 旧日志保存的最多数量 WithMaxAge() [默认: 保留所有旧日志] 旧日志保存的最长时间 WithLocalTime() [默认: true] true: 使用本地时间; false: 使用UTC时间
func NewRotatableWriteCloserWithSpec ¶ added in v2.1.9
func NewRotatableWriteCloserWithSpec(filePath string, spec string, options ...LumberjackOption) (io.WriteCloser, error)
NewRotatableWriteCloserWithSpec 满足条件(spec),执行Rotate().
PS: (1) 可能存在情况,Rotate()后,生成的旧日志文件大小为0B.
func NopCloserToReadSeeker ¶
func NopCloserToReadSeeker(readSeeker io.ReadSeeker) io.ReadSeekCloser
func NopCloserToReader ¶
func NopCloserToReader(reader io.Reader) io.ReadCloser
NopCloserToReader
PS: 返回值调用Close()将什么都不会做,直接返回nil.
func NopCloserToWriter ¶
func NopCloserToWriter(writer io.Writer) io.WriteCloser
NopCloserToWriter
PS: 返回值调用Close()将什么都不会做,直接返回nil.
func ReadFromReader ¶
ReadFromReader 读取io.Reader的内容(io.Reader => []byte)
func ToBufioReader ¶
ToBufioReader io.Reader 接口 => *bufio.Reader
作用: 可以调用 bufio.Reader 结构体的方法(因为 io.Reader 接口就一个Read方法).
func TryToClose ¶
TryToClose 尝试关闭(如果实现了io.Closer接口的话).
@param writers (1) 可以为nil(即不传参)
(2) 其中可以有nil
@return 发生error的话,返回第一个
Types ¶
type DailyWriteCloser ¶ added in v2.1.9
type DailyWriteCloser struct {
// contains filtered or unexported fields
}
func (*DailyWriteCloser) Close ¶ added in v2.1.9
func (dwc *DailyWriteCloser) Close() error
type LumberjackOption ¶
type LumberjackOption func(opts *lumberjackOptions)
func WithCompress ¶
func WithCompress(compress bool) LumberjackOption
func WithLocalTime ¶
func WithLocalTime(localTime bool) LumberjackOption
func WithMaxAge ¶
func WithMaxAge(maxAge time.Duration) LumberjackOption
func WithMaxBackups ¶
func WithMaxBackups(maxBackups int) LumberjackOption