logrotate

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 6 Imported by: 1

README

logrotate

GoDoc Build Status Coverage Status Go Report Card Issues

Utilities to support logfile rotation in Go (compatible with Linux 'logrotate').

Documentation

Overview

package logrotate provides a clean simple way to implement log file writing with rotation of the logfiles, e.g. after a certain time or beyond a certain size. Log rotation can depend on operating system signals and can be used with Linux 'logrotate'.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustLogWriterWithSignals added in v0.6.0

func MustLogWriterWithSignals(logName string, defaultWriter io.Writer) io.Writer

MustLogWriterWithSignals opens a log file for writing and attaches a signal handler (signals.RunOnPoke) to it. Therefore, when the program receives SIGHUP or SIGUSR1, it will close then reopen the log file, allowing log rotation to happen.

Note that the logName may be blank or "-", in which case the defaultWriter will be used instead of a log file; there is no signal handler in this case.

If an error arises, this will cause a panic.

func NewLogWriterWithSignals added in v0.6.0

func NewLogWriterWithSignals(logName string, defaultWriter io.Writer) (io.Writer, error)

NewLogWriterWithSignals opens a log file for writing and attaches a signal handler (signals.RunOnPoke) to it. Therefore, when the program receives SIGHUP or SIGUSR1, it will close then reopen the log file, allowing log rotation to happen.

Note that the logName may be blank or "-", in which case the defaultWriter will be used instead of a log file; there is no signal handler in this case.

Types

type ReopenWriter

type ReopenWriter interface {
	io.Writer
	io.Closer
	FileName() string
	Open() error
	WriteString(s string) (n int, err error)
}

ReopenWriter is a WriteCloser that is able to close and reopen cleanly whilst in use. It is intended for writing log files, so always appends to existing files instead of truncating them.

This will work well with the 'logrotate' utility on Linux. On rotation, 'logrotate' should rename the old file and then signal to the application, e.g. via SIGHUP or SIGUSR1.

func NewReopenWriter

func NewReopenWriter(fileName string) ReopenWriter

NewReopenWriter returns a new reopener with a given filename. The filename stays constant even when the file is closed and reopened.

Directories

Path Synopsis
package safe provides a thread-safe holder for a value that may be updated by multiple goroutines.
package safe provides a thread-safe holder for a value that may be updated by multiple goroutines.

Jump to

Keyboard shortcuts

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