Documentation ¶
Index ¶
- func GroupCheckDuration(duration time.Duration) func(*Group)
- func GroupHeadSizeLimit(limit int64) func(*Group)
- func GroupTotalSizeLimit(limit int64) func(*Group)
- type AutoFile
- type Group
- func (g *Group) Buffered() int
- func (g *Group) Close()
- func (g *Group) FlushAndSync() error
- func (g *Group) HeadSizeLimit() int64
- func (g *Group) MaxIndex() int
- func (g *Group) MinIndex() int
- func (g *Group) NewReader(index int) (*GroupReader, error)
- func (g *Group) OnStart() error
- func (g *Group) OnStop()
- func (g *Group) ReadGroupInfo() GroupInfo
- func (g *Group) Reset() error
- func (g *Group) RotateFile()
- func (g *Group) TotalSizeLimit() int64
- func (g *Group) Wait()
- func (g *Group) Write(p []byte) (nn int, err error)
- func (g *Group) WriteLine(line string) error
- type GroupInfo
- type GroupReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GroupCheckDuration ¶
GroupCheckDuration allows you to overwrite default groupCheckDuration.
func GroupHeadSizeLimit ¶
GroupHeadSizeLimit allows you to overwrite default head size limit - 10MB.
func GroupTotalSizeLimit ¶
GroupTotalSizeLimit allows you to overwrite default total size limit of the group - 1GB.
Types ¶
type AutoFile ¶
AutoFile automatically closes and re-opens file for writing. The file is automatically setup to close itself every 1s and upon receiving SIGHUP.
This is useful for using a log file with the logrotate tool.
func OpenAutoFile ¶
OpenAutoFile creates an AutoFile in the path (with random ID). If there is an error, it will be of type *PathError or *ErrPermissionsChanged (if file's permissions got changed (should be 0600)).
func (*AutoFile) Close ¶
Close shuts down the closing goroutine, SIGHUP handler and closes the AutoFile.
func (*AutoFile) Size ¶
Size returns the size of the AutoFile. It returns -1 and an error if fails get stats or open file. Opens AutoFile if needed.
type Group ¶
type Group struct { service.BaseService ID string Head *AutoFile // The head AutoFile to write to Dir string // Directory that contains .Head // contains filtered or unexported fields }
You can open a Group to keep restrictions on an AutoFile, like the maximum size of each chunk, and/or the total amount of bytes stored in the group.
The first file to be written in the Group.Dir is the head file.
Dir/ - <HeadPath>
Once the Head file reaches the size limit, it will be rotated.
Dir/ - <HeadPath>.000 // First rolled file - <HeadPath> // New head path, starts empty. // The implicit index is 001.
As more files are written, the index numbers grow...
Dir/ - <HeadPath>.000 // First rolled file - <HeadPath>.001 // Second rolled file - ... - <HeadPath> // New head path
The Group can also be used to binary-search for some line, assuming that marker lines are written occasionally.
func OpenGroup ¶
OpenGroup creates a new Group with head at headPath. It returns an error if it fails to open head file.
func (*Group) Close ¶
func (g *Group) Close()
Close closes the head file. The group must be stopped by this moment.
func (*Group) FlushAndSync ¶
FlushAndSync writes any buffered data to the underlying file and commits the current content of the file to stable storage (fsync).
func (*Group) HeadSizeLimit ¶
HeadSizeLimit returns the current head size limit.
func (*Group) NewReader ¶
func (g *Group) NewReader(index int) (*GroupReader, error)
NewReader returns a new group reader. CONTRACT: Caller must close the returned GroupReader.
func (*Group) OnStart ¶
OnStart implements service.Service by starting the goroutine that checks file and group limits.
func (*Group) OnStop ¶
func (g *Group) OnStop()
OnStop implements service.Service by stopping the goroutine described above. NOTE: g.Head must be closed separately using Close.
func (*Group) ReadGroupInfo ¶
Returns info after scanning all files in g.Head's dir.
func (*Group) RotateFile ¶
func (g *Group) RotateFile()
RotateFile causes group to close the current head and assign it some index. Note it does not create a new head.
func (*Group) TotalSizeLimit ¶
TotalSizeLimit returns total size limit of the group.
func (*Group) Wait ¶
func (g *Group) Wait()
Wait blocks until all internal goroutines are finished. Supposed to be called after Stop.
func (*Group) Write ¶
Write writes the contents of p into the current head of the group. It returns the number of bytes written. If nn < len(p), it also returns an error explaining why the write is short. NOTE: Writes are buffered so they don't write synchronously TODO: Make it halt if space is unavailable
type GroupInfo ¶
type GroupInfo struct { MinIndex int // index of the first file in the group, including head MaxIndex int // index of the last file in the group, including head TotalSize int64 // total size of the group HeadSize int64 // size of the head }
GroupInfo holds information about the group.
type GroupReader ¶
type GroupReader struct { *Group // contains filtered or unexported fields }
GroupReader provides an interface for reading from a Group.
func (*GroupReader) Close ¶
func (gr *GroupReader) Close() error
Close closes the GroupReader by closing the cursor file.
func (*GroupReader) CurIndex ¶
func (gr *GroupReader) CurIndex() int
CurIndex returns cursor's file index.
func (*GroupReader) Read ¶
func (gr *GroupReader) Read(p []byte) (n int, err error)
Read implements io.Reader, reading bytes from the current Reader incrementing index until enough bytes are read.
func (*GroupReader) SetIndex ¶
func (gr *GroupReader) SetIndex(index int) error
SetIndex sets the cursor's file index to index by opening a file at this position.