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 ¶
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 ¶
NewWithOptions will create a new *LogBuffer with the specified options. Each *LogBuffer must use a different Directory and HttpServeMux.
func (*LogBuffer) Dump ¶
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 ¶
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.
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