rotate

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 26, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

* rotate package provides a very simple tool to truncate a given file to 0 after it copies the last *configurable* part of this file to a new file with suffix .tail

The idea is that services need to have their log files (or redirection) be open in append mode. So truncation of the log file should be enough.

There is no grantee that some logs will be lost between the copying of the file tail and the truncation of the file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

func MaxSize

func MaxSize(size Size) Option

MaxSize of the file maximum size. If file size is bigger than this value, it will be truncated. Default to 20MB

func Suffix

func Suffix(suffix string) Option

Suffix of the tail before truncation, default to '.0'

func TailSize

func TailSize(size Size) Option

TailSize sets the size of the tail chunk that will be kept before the truncation. If value is bigger than MaxSize, it will be set to MaxSize. default to 10M

type Rotator

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

func NewRotator

func NewRotator(opt ...Option) Rotator

func (*Rotator) Rotate

func (r *Rotator) Rotate(file string) error

func (*Rotator) RotateAll

func (r *Rotator) RotateAll(dir string, names ...string) error

RotateAll will rotate all files in the directory if a set of names is given only named files will be rotated, other unknown files will be deleted

type Size

type Size int64
const (
	Bytes     Size = 1
	Kilobytes Size = 1024 * Bytes
	Megabytes Size = 1024 * Kilobytes
	Gigabyte  Size = 1024 * Megabytes
)

Jump to

Keyboard shortcuts

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