filerotate

package
v0.0.0-...-ddaf306 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSameDay

func IsSameDay(t1, t2 time.Time) bool

func IsSameHour

func IsSameHour(t1, t2 time.Time) bool

func MakeDailyRotateInDir

func MakeDailyRotateInDir(dir string, fileUniqueName string) func(time.Time, time.Time) string

func MakeHourlyRotateInDir

func MakeHourlyRotateInDir(dir string, fileUniqueName string) func(time.Time, time.Time) string

Types

type Config

type Config struct {
	DidClose           func(path string, didRotate bool)
	PathIfShouldRotate func(creationTime time.Time, now time.Time) string
}

type File

type File struct {
	sync.Mutex

	// Path is the path of the current file
	Path string
	// contains filtered or unexported fields
}

func New

func New(config *Config) (*File, error)

func NewDaily

func NewDaily(dir string, fileUniqueName string, didClose func(path string, didRotate bool)) (*File, error)

NewDaily creates a new file, rotating daily in a given directory

func NewHourly

func NewHourly(dir string, logUniqueName string, didClose func(path string, didRotate bool)) (*File, error)

NewHourly creates a new file, rotating hourly in a given directory

func (*File) Close

func (f *File) Close() error

func (*File) Sync

func (f *File) Sync() error

Sync commits the current contents of the file to stable storage.

func (*File) Write

func (f *File) Write(d []byte) (int, error)

Write writes data to a file

func (*File) Write2

func (f *File) Write2(d []byte, sync bool) (int64, int, error)

Write2 writes data to a file, optionally syncs to disk. To enable users to later seek to where the data was written, it returns offset at which the data was written, number of bytes and error. You can get path of the file from f.Path

Jump to

Keyboard shortcuts

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