Help us shape the future of Go! Take the 2026 Go Developer Survey

rotation

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

rotation

A file rotation package for Go.

Overview

  • Implements io.WriteCloser
  • Triggers file rotation by max-size or max-age
  • Limits the max number of rotated backups by max-backups

Installation

$ go get https://github.com/kanetch/rotation

Quick Start

import "github.com/kanetch/rotation"

func main() {
    w := rotation.NewSymlinkWriter(rotation.Config{})
    defer w.Close()

    w.Write([]byte("hello world\n"))
}

See also example/logger.

Settings

  • Path: path to symlink
  • MaxBackups: max number of retained backup files
  • MaxSize: rotation will be triggered when the current file size exceeds this value
  • MaxAge: rotation will be triggered when this value passes after previous rotation
  • FirstRotationTime: you can schedule daily rotation by using this and MaxAge
  • TimeFormat: suffix of file name

Documentation

Index

Constants

View Source
const (
	DefaultPath       = "log"             // ./log
	DefaultMaxBackups = 0                 // unlimited
	DefaultMaxSize    = 100 * 1024 * 1024 // 100 MB
	DefaultMaxAge     = 24 * time.Hour    // 1 day
	DefaultTimeFormat = "2006010215"      // yyyymmddhh
)

Default values

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path              string
	MaxBackups        int
	MaxSize           int64
	MaxAge            time.Duration
	FirstRotationTime time.Time
	TimeFormat        string
}

A Config is configurations to initialize a SymlinkWriter.

type SymlinkWriter

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

A SymlinkWriter implements io.WriteCloser.

func NewSymlinkWriter

func NewSymlinkWriter(c Config) *SymlinkWriter

NewSymlinkWriter creates a new SymlinkWriter.

func (*SymlinkWriter) Close

func (w *SymlinkWriter) Close() error

Close implements the io.Closer.

func (*SymlinkWriter) Write

func (w *SymlinkWriter) Write(p []byte) (int, error)

Write implements the io.Writer.

Directories

Path Synopsis
examples
logger command

Jump to

Keyboard shortcuts

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