logging

package
v2.3.5 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 18 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

IsTerminal returns whether the given file descriptor is a terminal

Functions

func InitContext

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

InitContext sets up standard Telepresence logging for a background process

func ShellString

func ShellString(exe string, args []string) string

Types

type Formatter

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

Formatter formats log messages for Telepresence client

func NewFormatter

func NewFormatter(timestampFormat string) *Formatter

func (*Formatter) Format

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements logrus.Formatter

type RotatingFile

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

func OpenRotatingFile

func OpenRotatingFile(
	logfilePath string,
	timeFormat string,
	localTime bool,
	captureStd bool,
	fileMode os.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 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

- captureStd: if true, override os.Stdout and os.Stderr with the file descriptor of the current logfile

- 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

Jump to

Keyboard shortcuts

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