Documentation ¶
Index ¶
- func CloseClosers(closers ...io.Closer) error
- func CloseReadClosers(readClosers ...io.ReadCloser) error
- func CloseReaders(readers ...io.Reader) error
- func CloseWriteClosers(writeClosers ...io.WriteCloser) error
- func CloseWriters(writers ...io.Writer) 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 NewDailyRotateRuleWriteCloser(filePath, delimiter string, days int, compress bool) (io.WriteCloser, error)deprecated
- func NewFileReader(filePath string) (*os.File, error)
- func NewLumberjackWriteCloser(filePath string, maxSize, maxBackups, maxAge int, localTime, compress bool) (io.WriteCloser, 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 NewRotateFileWriteCloser(filePath string, rotationTime, maxAge time.Duration, softLinkFlag bool) (io.WriteCloser, error)deprecated
- func NewRotateFileWriteCloserWithCount(filePath string, rotationTime time.Duration, rotationCount uint, ...) (io.WriteCloser, error)deprecated
- func NewSizeLimitRotateRuleWriteCloser(filePath, delimiter string, days, maxSize, maxBackups int, compress bool) (io.WriteCloser, error)deprecated
- func NopReadCloser(reader io.Reader) io.ReadCloser
- func NopWriteCloser(writer io.Writer) io.WriteCloser
- func ReadFromReader(reader io.Reader) ([]byte, error)
- func ToBufioReader(reader io.Reader) *bufio.Reader
- func WrapToReadCloser(reader io.Reader) io.ReadCloser
- func WrapToWriteCloser(writer io.Writer) io.WriteCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseClosers ¶
CloseClosers
PS: 就算循环过程中返回了非nil的error,也要继续向下循环(尽可能多地关闭).
@param closers (1) 可以为nil(即不传参);(2) 其中可以有nil @return 发生error的话,返回第一个
func CloseReadClosers ¶
func CloseReadClosers(readClosers ...io.ReadCloser) error
func CloseReaders ¶
CloseReaders
@param readers (1) 可以为nil(即不传参);(2) 其中可以有nil @return 发生error的话,返回第一个
func CloseWriteClosers ¶
func CloseWriteClosers(writeClosers ...io.WriteCloser) error
func CloseWriters ¶
CloseWriters 尝试关闭 传参writer(如果能关闭的话)
@param writers (1) 可以为nil(即不传参);(2) 其中可以有nil @return 发生error的话,返回第一个
func MultiWriteCloser ¶
func MultiWriteCloser(writeClosers ...io.WriteCloser) io.WriteCloser
MultiWriteCloser
PS: 参考了 io.MultiWriter().
func NewDailyRotateRuleWriteCloser
deprecated
func NewDailyRotateRuleWriteCloser(filePath, delimiter string, days int, compress bool) (io.WriteCloser, error)
NewDailyRotateRuleWriteCloser 调用了go-zero中的方法.
Deprecated: 调用完 Write() 后立即调用 Close() || 进程退出,Write的内容可能不会立即保存到文件中,导致丢失.
@param filePath 会自动创建父级目录;
文件不存在: 会创建; 文件已存在: (1)是个文件,会append;(2)是个目录,会返回error(e.g. open /Users/richelieu/Downloads: is a directory)
func NewFileReader ¶
NewFileReader
!!!:要在外部手动调用 *os.File 的Close方法.
@return os.File 结构体 实现了 io.Reader 接口
func NewLumberjackWriteCloser ¶ added in v1.3.11
func NewLumberjackWriteCloser(filePath string, maxSize, maxBackups, maxAge int, localTime, compress bool) (io.WriteCloser, error)
NewLumberjackWriteCloser
PS: (1) lumberjack: 日志切割组件.一般情况下,lumberjack配合其他日志库,实现日志的滚动(rolling)记录. (2) 根据 MaxBackups、MaxAge 删除过期文件,根据 Compress 决定是否压缩哪些未压缩的旧日志文件。
Golang 语言三方库 lumberjack 日志切割组件怎么使用?
https://mp.weixin.qq.com/s/gGnovwzS1ucW3Afxcytp_Q
go语言的日志滚动(rolling)记录器——lumberjack
https://zhuanlan.zhihu.com/p/430224518
@param filePath 日志路径,归档日志也会保存在对应目录下(若该值为空,则日志会保存到os.TempDir()目录下,日志文件名为<processname>-lumberjack.log)
(1) 会尝试创建父级目录; (2) 文件不存在,会自动创建; (3) 文件存在, (3.1) 是文件,内容追加在最后; (3.2) 是目录,返回error.
@param maxSize [单位: MB,默认: 100MB] 日志大小到达此值,就开始backup @param maxBackups 旧日志保存的最大数量,默认保存所有旧日志文件 @param maxAge [单位: days] 旧日志保存的最大天数,默认保存所有旧日志文件 @param localTime [默认使用UTC时间] 是否使用本地时间戳? @param compress [默认: false] 对backup的日志是否进行压缩
func NewReaderFromString ¶
func NewRotateFileWriteCloser
deprecated
func NewRotateFileWriteCloser(filePath string, rotationTime, maxAge time.Duration, softLinkFlag bool) (io.WriteCloser, error)
NewRotateFileWriteCloser 超时根据: maxAge
Deprecated: 推荐使用 NewLumberjackWriteCloser().
PS: (0) 写是线程安全的; (1) patternPath: 附带pattern的文件路径,e.g. "d:/test/test.%Y-%m-%d %H_%M_%S.log" (2) 只会输出到文件,并不会输出到控制台; (3) 第一个返回值,如果调用 CloseWriters() 后再调用 Write(),将返回error(invalid argument). (4) 如果filePath对应的文件已经存在,会追加在最后(并不会覆盖).
@param softLinkFlag true: 生成软链接(替身) @param toConsoleFlag true: 输出到文件日志的同时,也输出到控制台
e.g. ("aaa.log", time.Second*3, time.Second*30, true) => 最多同时存在 11 个日志文件(不算替身;30 / 3 + 1 = 11)
func NewRotateFileWriteCloserWithCount
deprecated
func NewSizeLimitRotateRuleWriteCloser
deprecated
func NewSizeLimitRotateRuleWriteCloser(filePath, delimiter string, days, maxSize, maxBackups int, compress bool) (io.WriteCloser, error)
NewSizeLimitRotateRuleWriteCloser 调用了go-zero中的方法.
Deprecated: 调用完 Write() 后立即调用 Close() || 进程退出,Write的内容可能不会立即保存到文件中,导致丢失.
PS: 最多生成文件的数量: maxBackups + 1(filePath)
@param filePath 会自动创建父级目录;
文件不存在: 会创建; 文件已存在: (1)是个文件,会append;(2)是个目录,会返回error(e.g. open /Users/richelieu/Downloads: is a directory)
@param delimiter 分隔符 @param maxSize 单位: MB @param maxBackups 备份数量的上限 @param compress 如果设置为true,compress前后各会输出一条信息(logx.Infof、logx.Errorf)
e.g. Mac环境
("test.log", "-", 1, 10, 3, true) 4个文件: test.log test-2023-03-10T16/50/11+08/00.log.gz test-2023-03-10T16/50/10+08/00.log.gz test-2023-03-10T16/50/09+08/00.log.gz
func NopReadCloser ¶
func NopReadCloser(reader io.Reader) io.ReadCloser
NopReadCloser
PS: 返回值调用Close()将什么都不会做,直接返回nil.
func NopWriteCloser ¶
func NopWriteCloser(writer io.Writer) io.WriteCloser
NopWriteCloser
PS: 返回值调用Close()将什么都不会做,直接返回nil.
func ReadFromReader ¶
ReadFromReader 读取io.Reader的内容(io.Reader => []byte)
func ToBufioReader ¶
ToBufioReader io.Reader 接口 => *bufio.Reader
作用: 可以调用 bufio.Reader 结构体的方法(因为 io.Reader 接口就一个Read方法).
func WrapToReadCloser ¶
func WrapToReadCloser(reader io.Reader) io.ReadCloser
func WrapToWriteCloser ¶
func WrapToWriteCloser(writer io.Writer) io.WriteCloser
Types ¶
This section is empty.