fs

package
v0.0.0-...-660a5ed Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logfile

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

Logfile struct defines the elements of a Logfile: a pointer to an os.File, as well as its path in a string format and an indicator on when to rotate this file (size in megabytes)

func New

func New(path string) (*Logfile, error)

NewLogFile function use the target file as a Logfile, as indicated in the path string; returning a pointer to a Logfile and an error.

If this file does not exist, then it will be created. If the file already exists, then it will be loaded -- and rotated if its too heavy.

func (*Logfile) IsTooHeavy

func (f *Logfile) IsTooHeavy() bool

IsTooHeavy method will verify the file's size and rotate it if exceeding the set maximum weight (in the Logfile's rotate element)

func (*Logfile) MaxSize

func (f *Logfile) MaxSize(mb int) *Logfile

MaxSize method will define the rotation indicator for the Logfile, or, the target size when should the logfile be rotated (in MBs)

func (*Logfile) Rotate

func (f *Logfile) Rotate() error

Rotate method will rename the existing (overweight) logfile to append a timestamp, and create a new Logfile based on the original filename. The new file will be the target of subsequent writes.

func (*Logfile) Size

func (f *Logfile) Size() (int64, error)

Size method is a wrapper for an os.File.Stat() followed by fs.FileInfo.Size()

func (*Logfile) Write

func (f *Logfile) Write(b []byte) (n int, err error)

Write method is defined to implement the io.Writer interface, for Logfile to be compatible with Logger as an output to be used

Jump to

Keyboard shortcuts

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