Documentation ¶
Index ¶
- Constants
- Variables
- func InitContext(ctx context.Context, name string, strategy RotationStrategy, captureStd bool) (context.Context, error)
- func LoadTimedLevelFromCache(ctx context.Context, tl log.TimedLevel, procName string) error
- func SetAndStoreTimedLevel(ctx context.Context, tl log.TimedLevel, level string, duration time.Duration, ...) error
- func SummarizeLog(ctx context.Context, name string) (string, error)
- type RotatingFile
- type RotationStrategy
- type SysInfo
Constants ¶
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.
const RotateNever = rotateNever(0)
The RotateNever strategy will always answer false to the RotateNow question.
Variables ¶
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 SetAndStoreTimedLevel ¶ added in v2.4.2
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) 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.
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)