rotate

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 6 Imported by: 1

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-200601%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 文件名格式,除了标准库支持的时间格式之外,还可以有以下占位符:

%i 表示同一时间段内的产生多个文件时的计数器。

比如:

2006-01-02-15-04-%i-01-02.log

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

func (*Rotate) Close

func (r *Rotate) Close() error

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