Documentation
¶
Overview ¶
Package rlog provides a minimal asynchronous logger tailored for high-throughput, best-effort recording of unstructured log messages. The package keeps the API surface tiny and accepts that queued log writes may block when downstream sinks stall.
Index ¶
- Constants
- func Auditf(format string, v ...interface{})
- func Close()
- func Debugf(format string, v ...interface{})
- func EnableDefaultLoggerForLogServer()
- func EnableDefaultLoggerForService()
- func EnableDefaultLoggerForUtility()
- func Errorf(format string, v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Infof(format string, v ...interface{})
- func IsDebugEnabled() bool
- func Warnf(format string, v ...interface{})
- type BufferedSink
- type ConsoleWriter
- type FileWriter
- type LogFormatter
- func (self *LogFormatter) Auditf(format string, a ...interface{})
- func (self *LogFormatter) Close()
- func (self *LogFormatter) Debugf(format string, a ...interface{})
- func (self *LogFormatter) Errorf(format string, a ...interface{})
- func (self *LogFormatter) Flush()
- func (self *LogFormatter) Infof(format string, a ...interface{})
- func (self *LogFormatter) IsEnabled(level int) bool
- func (self *LogFormatter) Log(when time.Time, level int, message string)
- func (self *LogFormatter) Warnf(format string, a ...interface{})
- type LogSink
- type Logger
- type MultiWriter
- type NopSink
Constants ¶
const ( // Debug is the most verbose log level, intended for temporary diagnostic noise. Debug = 0 // Info emits general information about application progress. Info = 1 // Audit is for high-level business events that operators prefer to see by default. Audit = 2 // Warn signals unexpected situations that the application can recover from. Warn = 3 // Error indicates failures that require attention. Error = 4 )
Variables ¶
This section is empty.
Functions ¶
func Auditf ¶
func Auditf(format string, v ...interface{})
Auditf logs using fmt.Sprintf semantics at Audit level.
func Close ¶
func Close()
Close releases resources owned by the global logger and replaces it with a no-op logger.
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf logs using fmt.Sprintf semantics at Debug level.
func EnableDefaultLoggerForLogServer ¶
func EnableDefaultLoggerForLogServer()
EnableDefaultLoggerForLogServer configures the global logger for log-forwarding processes that only need durable file storage.
func EnableDefaultLoggerForService ¶
func EnableDefaultLoggerForService()
EnableDefaultLoggerForService configures the global logger for services that run continuously, defaulting to warning level output on the console.
func EnableDefaultLoggerForUtility ¶
func EnableDefaultLoggerForUtility()
EnableDefaultLoggerForUtility configures the global logger for short-lived command line utilities. It combines console output with a buffered file sink.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf logs using fmt.Sprintf semantics at Error level.
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf logs the message at error level and exits the process with status 1.
func Infof ¶
func Infof(format string, v ...interface{})
Infof logs using fmt.Sprintf semantics at Info level.
func IsDebugEnabled ¶
func IsDebugEnabled() bool
IsDebugEnabled reports whether the default logger has the Debug level enabled.
Types ¶
type BufferedSink ¶
type BufferedSink struct {
// contains filtered or unexported fields
}
BufferedSink decouples producers from downstream sinks by writing log entries into a bounded channel. The background goroutine periodically flushes the downstream sink to amortize I/O calls.
func NewBufferedSink ¶
func NewBufferedSink(size int, downstream LogSink) *BufferedSink
NewBufferedSink constructs a bounded queue backed sink. When the queue is full producers block until there is space, trading off log retention for back pressure.
func (*BufferedSink) Close ¶
func (self *BufferedSink) Close()
func (*BufferedSink) Flush ¶
func (self *BufferedSink) Flush()
func (*BufferedSink) IsEnabled ¶
func (self *BufferedSink) IsEnabled(level int) bool
type ConsoleWriter ¶
type ConsoleWriter struct {
// contains filtered or unexported fields
}
ConsoleWriter renders log lines to the process STDOUT. When STDOUT is detected as an interactive terminal it applies ANSI colors to warn and error messages.
func NewConsoleWriter ¶
func NewConsoleWriter(minLevel int) *ConsoleWriter
NewConsoleWriter creates a console sink that only prints messages at or above the provided log level.
func (*ConsoleWriter) Close ¶
func (self *ConsoleWriter) Close()
func (*ConsoleWriter) Flush ¶
func (self *ConsoleWriter) Flush()
func (*ConsoleWriter) IsEnabled ¶
func (self *ConsoleWriter) IsEnabled(level int) bool
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter appends log records to rolling log files on disk. Rotation occurs once the active file exceeds maxFileSize bytes.
func NewFileWriter ¶
func NewFileWriter(filename string, maxSize int64) *FileWriter
NewFileWriter creates a writer that rotates when the file exceeds maxSize bytes. When filename is empty it derives the executable name automatically.
func (*FileWriter) Close ¶
func (self *FileWriter) Close()
func (*FileWriter) Flush ¶
func (self *FileWriter) Flush()
func (*FileWriter) IsEnabled ¶
func (self *FileWriter) IsEnabled(level int) bool
type LogFormatter ¶
type LogFormatter struct {
// contains filtered or unexported fields
}
LogFormatter marshals formatted log messages and forwards them to the sink. It optionally annotates records with caller file/line metadata.
func (*LogFormatter) Auditf ¶
func (self *LogFormatter) Auditf(format string, a ...interface{})
func (*LogFormatter) Close ¶
func (self *LogFormatter) Close()
func (*LogFormatter) Debugf ¶
func (self *LogFormatter) Debugf(format string, a ...interface{})
func (*LogFormatter) Errorf ¶
func (self *LogFormatter) Errorf(format string, a ...interface{})
func (*LogFormatter) Flush ¶
func (self *LogFormatter) Flush()
func (*LogFormatter) Infof ¶
func (self *LogFormatter) Infof(format string, a ...interface{})
func (*LogFormatter) IsEnabled ¶
func (self *LogFormatter) IsEnabled(level int) bool
func (*LogFormatter) Warnf ¶
func (self *LogFormatter) Warnf(format string, a ...interface{})
type LogSink ¶
type LogSink interface {
IsEnabled(level int) bool // reentrant
Log(when time.Time, level int, message string)
Flush()
Close()
}
LogSink represents a destination for log records. Implementations are invoked by the thread-safe LogFormatter, so they do not need their own synchronization unless they perform internal background work. Non-blocking behavior is still encouraged to keep log calls responsive.
type Logger ¶
type Logger interface {
LogSink
Debugf(format string, a ...interface{})
Infof(format string, a ...interface{})
Auditf(format string, a ...interface{})
Warnf(format string, a ...interface{})
Errorf(format string, a ...interface{})
}
Logger represents the public logging surface. All methods are concurrency-safe and forward to the wrapped LogSink implementation.
func GetDefaultLogger ¶
func GetDefaultLogger() Logger
GetDefaultLogger returns the globally configured logger.
func NewDefaultForService ¶
func NewDefaultForService() Logger
NewDefaultForService combines console and file sinks for long-running daemons.
func NewDefaultLogToConsole ¶
NewDefaultLogToConsole returns a convenience logger that writes to STDOUT/STDERR using the ConsoleWriter with the supplied minimum log level.
type MultiWriter ¶
type MultiWriter struct {
// contains filtered or unexported fields
}
MultiWriter fans records out to two sinks. It is useful when the same log stream needs both a durable and an interactive destination.
func NewMultiWriter ¶
func NewMultiWriter(first, second LogSink) MultiWriter
NewMultiWriter constructs a composite sink that duplicates log records to both provided sinks.
func (MultiWriter) Close ¶
func (self MultiWriter) Close()
func (MultiWriter) Flush ¶
func (self MultiWriter) Flush()
func (MultiWriter) IsEnabled ¶
func (self MultiWriter) IsEnabled(level int) bool