rotation

package
v1.121.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MPL-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package rotation provides file rotation when files hit a given size.

Index

Constants

View Source
const (
	DefaultMaxSize    = 10 * 1024 * 1024
	DefaultMaxBackups = 1
)

Constants for defaults.

Variables

View Source
var PathToLog string

PathToLog holds the path to the log file that was configured on the command line when using ParseAndSetup().

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns the default path that will be used. This will use cmdline.AppIdentifier (if set) to better isolate the log location.

func MaxBackups

func MaxBackups(maxBackups int) func(*Rotator) error

MaxBackups sets the maximum number of old log files to retain. Defaults to DefaultMaxBackups.

func MaxSize

func MaxSize(maxSize int64) func(*Rotator) error

MaxSize sets the maximum size of the log file before it gets rotated. Defaults to DefaultMaxSize.

func ParseAndSetupLogging added in v1.96.0

func ParseAndSetupLogging(cl *cmdline.CmdLine, consoleOnByDefault bool) []string

ParseAndSetupLogging adds command-line options for controlling logging, parses the command line, then instantiates a rotator and attaches it to slog. Returns the remaining arguments that weren't used for option content. If consoleOnByDefault is true, then logs will also go to the console by default, but an option to turn them off will be added to the command line flags. Conversely, if it is false, an option to turn them on will be added to the command line flags.

func Path

func Path(path string) func(*Rotator) error

Path specifies the file to write logs to. Backup log files will be retained in the same directory. Defaults to the value of DefaultPath().

func WithMask added in v1.40.0

func WithMask(mask os.FileMode) func(*Rotator) error

WithMask sets the mask when creating files, which have the unmasked mode of 0644, and directories, which have the unmasked mode of 0755. Defaults to 0777.

Types

type Rotator

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

Rotator holds the rotator data.

func New

func New(options ...func(*Rotator) error) (*Rotator, error)

New creates a new Rotator with the specified options.

func (*Rotator) Close

func (r *Rotator) Close() error

Close implements io.Closer.

func (*Rotator) PathToLog added in v1.75.0

func (r *Rotator) PathToLog() string

PathToLog returns the path to the log file that will be used.

func (*Rotator) Sync added in v1.95.0

func (r *Rotator) Sync() error

Sync commits the current contents of the file to stable storage.

func (*Rotator) Write

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

Write implements io.Writer.

Jump to

Keyboard shortcuts

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