logfilerotator

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: MIT Imports: 7 Imported by: 0

README

logfilerotator

logfilerotator provides log file rotating functionality in Go with io.Writer interface which make it very easy to integrate with other Go packages.

Documentation

Overview

Package logfilerotator provides log file rotating functionality in Go with io.Writer interface which make it very easy to integrate with other Go packages. logfilerotator 是一个具有日志文件切割功能的 io.Writer 接口实现,非常容易与其他Go模块集成。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogFileRotator

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

LogFileRotator 日志文件Writer

func New

func New(logPath string, rotate RotateStrategy) *LogFileRotator

New 创建一个 LogFileRotator

func NewStderr

func NewStderr() *LogFileRotator

NewStderr 创建一个输出到 os.Stderr 的 LogFileRotator

func (*LogFileRotator) Write

func (r *LogFileRotator) Write(b []byte) (int, error)

Write 实现 io.Writer 接口,带日志切割功能

type RotateStrategy

type RotateStrategy string

RotateStrategy 日志切割策略 建议策略为 hourfile/dayfile ,因为 hour/day 策略 rsyslog 收集日志有时候会感知不到新文件

const (
	// "hour" : 总是往基准路径写日志,遇到整点将基准文件重命名为带上一小时标记的文件名,再创建基准路径文件写入日志
	RotateStrategyHour RotateStrategy = "hour"
	// "day" : 总是往基准路径写日志,遇到零点将基准文件重命名为带上一天标记的文件名,再创建基准路径文件写入日志
	RotateStrategyDay RotateStrategy = "day"
	// "hourfile" : 总是往"基准路径.YYYYMMDDHH"写日志内容,遇到整点创建新的日志文件. 此为默认策略
	RotateStrategyHourFile RotateStrategy = "hourfile"
	// "dayfile" : 总是往"基准路径.YYYYMMDD"写日志内容,遇到零点创建新的日志文件
	RotateStrategyDayFile RotateStrategy = "dayfile"
	// "none" : 总是往基准路径写日志,不切割
	RotateStrategyNone RotateStrategy = "none"
)

Jump to

Keyboard shortcuts

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