flog

package
v0.0.0-...-62a3dc9 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: BSD-2-Clause Imports: 14 Imported by: 1

Documentation

Overview

Package flog provides facilities for using and managing file-backed logger objects.

Index

Constants

View Source
const (
	FLUSH_DEFAULTS = iota
	FLUSH_FORCED
)
View Source
const (
	BufferedFile = iota
	DirectFile
)

Enumeration of different FLog implementations.

View Source
const DefaultFlushIntervalSec = 5

Default flush interval, in seconds, for BufferedLog instances.

View Source
const FLogOpenFlags = os.O_RDWR | os.O_APPEND | os.O_CREATE

Log file open flags.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedLog

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

BufferedLog represents a buffered, file-backed logger and enforces a standardized logging format. New logging entries are sent to a memory buffer and periodically flushed to the backing file at configurable intervals by a separate goroutine.

func (*BufferedLog) BaseDir

func (this *BufferedLog) BaseDir() string

BaseDir returns the base directory of the file backing this BufferedLog instance.

func (*BufferedLog) BufferCap

func (this *BufferedLog) BufferCap() int

BufferCap returns the current capacity of the underlying memory buffer.

func (*BufferedLog) Close

func (this *BufferedLog) Close()

Close disables the BufferedLog instance, flushes any remaining entries to disk, and then closes the backing log file.

func (*BufferedLog) FlushIntervalSec

func (this *BufferedLog) FlushIntervalSec() int32

FlushInterval returns the interval between log flushes in seconds.

func (*BufferedLog) Name

func (this *BufferedLog) Name() string

Name returns the friendly name of the log.

func (*BufferedLog) Print

func (this *BufferedLog) Print(msg *xlog.LogMsg)

Print formats and buffers a new log entry as long as the BufferedLog instance is enabled.

func (*BufferedLog) SetEnabled

func (this *BufferedLog) SetEnabled(enabled bool)

SetEnabled temporarily enables/disables the log instance.

func (*BufferedLog) SetFlushIntervalSec

func (this *BufferedLog) SetFlushIntervalSec(interval int32)

SetFlushIntervalSec sets the interval at which the log buffer worker will attempt to flush new entries into the backing log file.

type DirectLog

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

DirectLog represents a file-backed logger and enforces a standardized logging format. New logging entries are written immediately to the backing file.

func (*DirectLog) BaseDir

func (this *DirectLog) BaseDir() string

BaseDir returns the base directory of the file backing this DirectLog instance.

func (*DirectLog) Close

func (this *DirectLog) Close()

Close disables the DirectLog instance, flushes any remaining entries to disk, and then closes the backing log file.

func (*DirectLog) Name

func (this *DirectLog) Name() string

Name returns the friendly name of the log.

func (*DirectLog) Print

func (this *DirectLog) Print(msg *xlog.LogMsg)

Print formats and buffers a new log entry as long as the DirectLog instance is enabled.

func (*DirectLog) SetEnabled

func (this *DirectLog) SetEnabled(enabled bool)

SetEnabled temporarily enables/disables the DirectLog instance.

type FLog

type FLog interface {
	BaseDir() string
	Close()
	SetEnabled(bool)
	Name() string
	Print(msg *xlog.LogMsg)
}

FLog provides a common interface for different file-backed logs. This package includes two primary implementations; BufferedLog and DirectLog.

func New

func New(name, logPath string, logType int) FLog

New returns a new FLog instance of the requested type. The backing log file is created or opened for append.

func Rotate

func Rotate(log FLog) FLog

Rotate takes a given FLog instance, closes it, timestamps and moves the backing log file into an old subdirectory, before opening and returning a new FLog instance at the original location.

Jump to

Keyboard shortcuts

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