flog

package module
v0.0.0-...-8c56ce0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2018 License: BSD-2-Clause Imports: 13 Imported by: 0

README

FLog

Overview

FLog is a Go package which provides file-backed logging capabilities for go applications. FLog is built on top of the standard log library, and includes facilities for buffered logging, managing separate logs and log files, as well as periodic log rotation.

License

This Go package is release under a BSD-style license, the contents of which are in the repo's LICENSE file.

API Documentation

http://godoc.org/github.com/xaevman/flog

Documentation

Overview

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

Index

Constants

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 FLogFlags = log.Ldate | log.Lmicroseconds

Logger format flags.

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

Log file open flags.

Variables

View Source
var FlogCallDepth = 3

FlogCallDepth is used to determine how far up the callstack to look for the calling file:line information when formatting log messages.

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 seperate goroutine.

func (*BufferedLog) BaseDir

func (this *BufferedLog) BaseDir() string

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

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) Disable

func (this *BufferedLog) Disable()

Disable temporarily disables the BufferedLog instance. New calls to Print will have no effect.

func (*BufferedLog) Enable

func (this *BufferedLog) Enable()

Enable re-enables an BufferedLog instance.

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(format string, v ...interface{})

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

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) Disable

func (this *DirectLog) Disable()

Disable temporarily disables the DirectLog instance. New calls to Print will have no effect.

func (*DirectLog) Enable

func (this *DirectLog) Enable()

Enable re-enables an DirectLog instance.

func (*DirectLog) Name

func (this *DirectLog) Name() string

Name returns the friendly name of the log.

func (*DirectLog) Print

func (this *DirectLog) Print(format string, v ...interface{})

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

type FLog

type FLog interface {
	BaseDir() string
	Close()
	Disable()
	Enable()
	Name() string
	Print(format string, v ...interface{})
}

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