logbuf

package
v0.0.0-...-63c3a42 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package logbuf provides a circular buffer for writing logs to.

Package logbuf provides an io.Writer which can be passed to the log.New function to serve as a destination for logs. Logs can be viewed via a HTTP interface and may also be directed to the standard error output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UseFlagSet

func UseFlagSet(set *flag.FlagSet)

UseFlagSet instructs this package to read its command-line flags from the given flag set instead of from the command line. Caller must pass the flag set to this method before calling Parse on it.

Types

type LogBuffer

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

LogBuffer is a circular buffer suitable for holding logs. It satisfies the io.Writer interface. It is usually passed to the log.New function.

func Get

func Get() *LogBuffer

Get works like New except that successive calls to Get return the same instance.

func New

func New() *LogBuffer

New returns a new *LogBuffer with the standard options. Note that RedirectStderr will be set to true if AlsoLogToStderr is false. Only one should be created per application.

func NewWithOptions

func NewWithOptions(options Options) *LogBuffer

NewWithOptions will create a new *LogBuffer with the specified options. Each *LogBuffer must use a different Directory and HttpServeMux.

func (*LogBuffer) Dump

func (lb *LogBuffer) Dump(writer io.Writer, prefix, postfix string,
	recentFirst bool) error

Dump will write the contents of the log buffer to w, with a prefix and postfix string written before and after each line. If recentFirst is true, the most recently written contents are dumped first.

func (*LogBuffer) Flush

func (lb *LogBuffer) Flush() error

Flush flushes the open log file (if one is open). This should only be called just prior to process termination. The log file is automatically flushed after short periods of inactivity.

func (*LogBuffer) Write

func (lb *LogBuffer) Write(p []byte) (n int, err error)

Write will write len(p) bytes from p to the log buffer. It always returns len(p), nil.

func (*LogBuffer) WriteHtml

func (lb *LogBuffer) WriteHtml(writer io.Writer)

WriteHtml will write the contents of the log buffer to writer, with appropriate HTML markups.

type Options

type Options struct {
	AlsoLogToStderr bool
	Directory       string
	HttpServeMux    *http.ServeMux
	IdleMarkTimeout time.Duration
	MaxBufferLines  uint          // Minimum: 100.
	MaxFileSize     flagutil.Size // Minimum: 16 KiB
	Quota           flagutil.Size // Minimum: 64 KiB.
	RedirectStderr  bool          // Only one LogBuffer should set this.
}

func GetStandardOptions

func GetStandardOptions() Options

GetStandardOptions will return the standard options. Only one *LogBuffer should be created per application with these options. The following command-line flags are registered and used:

-alsoLogToStderr: If true, also write logs to stderr
-logbufLines:     Number of lines to store in the log buffer
-logDir:          Directory to write log data to. If empty, no logs are
                  written
-logFileMaxSize:  Maximum size for each log file. If exceeded, the logfile
                  is closed and a new one opened.
                  If zero, the limit will be 16 KiB
-logQuota:        Log quota. If exceeded, old logs are deleted.
                  If zero, the quota will be 64 KiB

Jump to

Keyboard shortcuts

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