rotate

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: MIT Imports: 11 Imported by: 0

README

rotate GoDoc Build Status

Rotation for *os.File.

Installation

go get -u github.com/koorgoo/rotate

Quick Start

f := rotate.MustOpen(name, rotate.Config{
  Bytes: rotate.MB,
  Count: 10,
})
defer f.Close()

See examples.

Documentation

Index

Constants

View Source
const (
	B  int64 = 1
	KB       = 1024 * B
	MB       = 1024 * KB
	GB       = 1024 * MB
)

Common bytes.

View Source
const OpenFlag int = os.O_APPEND | os.O_CREATE | os.O_WRONLY

OpenFlag is used to open a file after rotation.

View Source
const OpenPerm os.FileMode = 0644

OpenPerm is used in *Open shortcuts to create a file.

View Source
const SuffixRe = `(\.[1-9]+)?$`

SuffixRe is a pattern of rotation counter suffix.

Variables

View Source
var ErrNotSupported = fmt.Errorf("rotate: not supported on %s", runtime.GOOS)

ErrNotSupported is returned when rotation is not supported on a current system.

Functions

func Dirname

func Dirname(fd uintptr) (string, error)

Dirname returns a directory containing fd.

func List

func List(root, name string) ([]string, error)

List returns a sorted list of names of existing files which end with SuffixRe. If name exists, it is the first item in result.

func Split

func Split(name string) (base string, n int64)

Split splits name into base part and rotation counter. When name cannot be splitted, base equals name.

Types

type Config

type Config struct {
	// Bytes sets soft limit for file size.
	// Soft limit may be exceeded to write a message to a single file.
	// If Bytes == 0, no rotation happens.
	Bytes int64
	// Count defines the maximum amount of files (open + rotated).
	// If Count <= 1, a file will be removed & created on Bytes size.
	Count int64
	// Lock defines whether to lock on write.
	// Must be set for asynchronous writes.
	Lock bool
}

Config defines rotating policy.

type Error

type Error struct {
	Filename string
	Err      error
}

Error is returned when rotation fails. It does not cancel write.

func (*Error) Error

func (e *Error) Error() string

type File

type File interface {
	io.Writer
	io.Closer

	Fd() uintptr
	Name() string
	Stat() (os.FileInfo, error)
	Sync() error
	WriteString(string) (int, error)
}

File is an interface compatible with *os.File.

func MustOpen

func MustOpen(name string, c Config) File

MustOpen is like Open, but panics on error. ErrNotSupported is skipped.

func MustWrap

func MustWrap(f File, c Config) File

MustWrap is like Wrap, but panics on error. ErrNotSupported is skipped.

func Open

func Open(name string, c Config) (File, error)

Open opens a file and wraps it.

func Wrap

func Wrap(f File, c Config) (File, error)

Wrap wraps f with Rotator instance and returns File.

type Rotator

type Rotator interface {
	Rotate() (File, error)
}

Rotator is an interface for file rotation.

func New

func New(f File, count int64) (r Rotator, err error)

New returns Rotator for f.

func Noop

func Noop(f File) Rotator

Noop return a noop Rotator.

Directories

Path Synopsis
log
zap

Jump to

Keyboard shortcuts

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