Package logger
Overview ▹
Index ▹
func LevelFilter ¶
func LevelFilter() *logutils.LevelFilter
LevelFilter returns a LevelFilter that is configured with the log levels that we use.
func Setup ¶
func Setup(config *Config, ui cli.Ui) (*logutils.LevelFilter, *GatedWriter, *LogWriter, io.Writer, bool)
Setup is used to perform setup of several logging objects:
* A LevelFilter is used to perform filtering by log level. * A GatedWriter is used to buffer logs until startup UI operations are
complete. After this is flushed then logs flow directly to output destinations.
* A LogWriter provides a mean to temporarily hook logs, such as for running
a command like "consul monitor".
* An io.Writer is provided as the sink for all logs to flow to.
The provided ui object will get any log messages related to setting up logging itself, and will also be hooked up to the gated logger. The final bool parameter indicates if logging was set up successfully.
func ValidateLevelFilter ¶
func ValidateLevelFilter(minLevel logutils.LogLevel, filter *logutils.LevelFilter) bool
ValidateLevelFilter verifies that the log levels within the filter are valid.
type Config ¶
Config is used to set up logging.
type Config struct { // LogLevel is the minimum level to be logged. LogLevel string // EnableSyslog controls forwarding to syslog. EnableSyslog bool // SyslogFacility is the destination for syslog forwarding. SyslogFacility string }
type GatedWriter ¶
GatedWriter is an io.Writer implementation that buffers all of its data into an internal buffer until it is told to let data through.
type GatedWriter struct {
Writer io.Writer
// contains filtered or unexported fields
}
func (*GatedWriter) Flush ¶
func (w *GatedWriter) Flush()
Flush tells the GatedWriter to flush any buffered data and to stop buffering.
func (*GatedWriter) Write ¶
func (w *GatedWriter) Write(p []byte) (n int, err error)
type LogHandler ¶
LogHandler interface is used for clients that want to subscribe to logs, for example to stream them over an IPC mechanism
type LogHandler interface { HandleLog(string) }
type LogWriter ¶
LogWriter implements io.Writer so it can be used as a log sink. It maintains a circular buffer of logs, and a set of handlers to which it can stream the logs to.
type LogWriter struct {
sync.Mutex
// contains filtered or unexported fields
}
func NewLogWriter ¶
func NewLogWriter(buf int) *LogWriter
NewLogWriter creates a LogWriter with the given buffer capacity
func (*LogWriter) DeregisterHandler ¶
func (l *LogWriter) DeregisterHandler(lh LogHandler)
DeregisterHandler removes a LogHandler and prevents more invocations
func (*LogWriter) RegisterHandler ¶
func (l *LogWriter) RegisterHandler(lh LogHandler)
RegisterHandler adds a log handler to receive logs, and sends the last buffered logs to the handler
func (*LogWriter) Write ¶
func (l *LogWriter) Write(p []byte) (n int, err error)
Write is used to accumulate new logs
type SyslogWrapper ¶
SyslogWrapper is used to cleanup log messages before writing them to a Syslogger. Implements the io.Writer interface.
type SyslogWrapper struct {
// contains filtered or unexported fields
}
func (*SyslogWrapper) Write ¶
func (s *SyslogWrapper) Write(p []byte) (int, error)
Write is used to implement io.Writer