rotate

package
v2.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package rotate 提供一个可以按文件大小进行分割的 io.Writer 实例。

Index

Constants

This section is empty.

Variables

View Source
var ErrIndexNotExists = errors.New("必须存在 %i")

ErrIndexNotExists 格式化字符串 %i 不存在

Functions

This section is empty.

Types

type Rotate

type Rotate struct {
	// contains filtered or unexported fields
}

Rotate 可按大小进行分割的文件

import "log"
// 每个文件以 100M 大小进行分割,以日期名作为文件名保存在 /var/log 下。
f,_ := NewRotate("debug-%y%m%i", "/var/log", 100*1024*1024)
l := log.New(f, "DEBUG", log.LstdFlags)

func New

func New(format, dir string, size int64) (*Rotate, error)

New 新建 Rotate

format 文件名格式,可以包含以下格式内容:

%y 表示两位数的年份;
%Y 四位数的年份;
%m 表示月份;
%d 表示当前月中的第几天;
%h 表示 12 进制的小时;
%H 表示 24 进制的小时;
%i 表示同一时间段内的,多个的文件的计数器。

dir 为文件保存的目录,若不存在会尝试创建。 size 为每个文件的最大尺寸,单位为 byte。

func (*Rotate) Close

func (r *Rotate) Close() error

Close 关闭文件

func (*Rotate) Flush

func (r *Rotate) Flush()

Flush 实现接口 Flusher.Flush()

func (*Rotate) Write

func (r *Rotate) Write(buf []byte) (int, error)

Jump to

Keyboard shortcuts

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