logging

package
v2.20.0-test.4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const RotateDaily = rotateDaily(0)

The RotateDaily strategy will ensure that the file is rotated if it is of non-zero size when a call to Write() arrives on a day different from the day when the current file was created.

View Source
const RotateNever = rotateNever(0)

The RotateNever strategy will always answer false to the RotateNow question.

Variables

View Source
var IsTerminal = term.IsTerminal //nolint:gochecknoglobals // os specific func replacement

IsTerminal returns whether the given file descriptor is a terminal.

Functions

func InitContext

func InitContext(ctx context.Context, name string, strategy RotationStrategy, captureStd bool) (context.Context, error)

InitContext sets up standard Telepresence logging for a background process.

func LoadTimedLevelFromCache added in v2.4.2

func LoadTimedLevelFromCache(ctx context.Context, tl log.TimedLevel, procName string) error

func SetAndStoreTimedLevel added in v2.4.2

func SetAndStoreTimedLevel(ctx context.Context, tl log.TimedLevel, level string, duration time.Duration, procName string) error

func SummarizeLog added in v2.4.0

func SummarizeLog(ctx context.Context, name string) (string, error)

Types

type RotatingFile

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

func OpenRotatingFile

func OpenRotatingFile(
	ctx context.Context,
	logfilePath string,
	timeFormat string,
	localTime bool,
	fileMode fs.FileMode,
	strategy RotationStrategy,
	maxFiles uint16,
) (*RotatingFile, error)

OpenRotatingFile opens a file with the given name after first having created the directory that it resides in and all parent directories. The file is opened write only.

Parameters:

- dirName: full path to the directory of the log file and its backups

- fileName: name of the file that should be opened (relative to dirName)

- timeFormat: the format to use for the timestamp that is added to rotated files

- localTime: if true, use local time in timestamps, if false, use UTC

- stdLogger: if not nil, all writes to os.Stdout and os.Stderr will be redirected to this logger as INFO level messages prefixed with <stdout> or <stderr>

- fileMode: the mode to use when creating new files the file

- strategy: determines when a rotation should take place

- maxFiles: maximum number of files in rotation, including the currently active logfile. A value of zero means unlimited.

func (*RotatingFile) BirthTime

func (rf *RotatingFile) BirthTime() time.Time

BirthTime returns the time when the current file was created. The time will be local if the file was opened with localTime == true and UTC otherwise.

func (*RotatingFile) Close

func (rf *RotatingFile) Close() error

Close implements io.Closer.

func (*RotatingFile) Rotate

func (rf *RotatingFile) Rotate() (err error)

Rotate closes the currently opened file and renames it by adding a timestamp between the file name and its extension. A new file empty file is then opened to receive subsequent data.

func (*RotatingFile) Size

func (rf *RotatingFile) Size() int64

Size returns the size of the current file.

func (*RotatingFile) Write

func (rf *RotatingFile) Write(data []byte) (int, error)

Write implements io.Writer.

type RotationStrategy

type RotationStrategy interface {
	RotateNow(file *RotatingFile, writeSize int) bool
}

A RotationStrategy answers the question if it is time to rotate the file now. It is called prior to every write so it needs to be fairly quick.

func NewRotateOnce

func NewRotateOnce() RotationStrategy

type SysInfo added in v2.4.0

type SysInfo interface {
	fmt.Stringer

	Size() int64

	BirthTime() time.Time
	ModifyTime() time.Time // most recent content change
	ChangeTime() time.Time // most recent metadata change

	SetOwnerAndGroup(name string) error

	HaveSameOwnerAndGroup(SysInfo) bool
}

SysInfo represents the elaborate info in a FileInfo.Sys(). The implementations are os specific.

Unix:

info.Sys().(*syscall.Stat_t)

Windows:

info.Sys().(*syscall.Win32FileAttributeData)

func FStat added in v2.4.3

func FStat(file dos.File) (SysInfo, error)

FStat returns the file status/info of an open file.

Jump to

Keyboard shortcuts

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