logfile

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logfile writes a site's log to plain files that rotate, so that the log never takes more than a set amount of disk.

Index

Constants

View Source
const (
	DefaultMaxSize = 10_000_000
	DefaultFiles   = 3
)

The cap of a site's log when its site file does not say: 3 files of 10 MB.

View Source
const (
	MinSize  = 1000
	MaxFiles = 100
)

Bounds of what a site file may ask for.

Variables

This section is empty.

Functions

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize reads a size such as "10MB", "500kB" or "1GB" into bytes.

func Paths

func Paths(path string) []string

Paths returns the files of the log at path that exist, oldest first.

func Remove

func Remove(path string) error

Remove deletes every file of the log at path.

func Rotated

func Rotated(path string) string

Rotated returns the name of the file the log at path was last rotated to.

Types

type Writer

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

Writer appends to a log file and rotates it when it is full: the file is renamed to <path>.1, what was <path>.1 to <path>.2, and so on, and the oldest file is deleted. Every Write should be one or more whole lines.

func Open

func Open(path string, maxSize int64, files int) (*Writer, error)

Open opens the log at path for appending. At most files files are kept, the current one included, each of at most maxSize bytes. Zero stands for the defaults.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the log.

func (*Writer) Write

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

Write appends p, rotating first when p would take the file past its cap.

Jump to

Keyboard shortcuts

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