Documentation ¶
Index ¶
- Constants
- func MustCreateSyslogger(prio syslog.Priority, flags int) *log.Logger
- func NewTestCommandLineLogger() (*LeveledLogger, *LogBuffer)
- func NewTestLogger(prefix string) (*LeveledLogger, *LogBuffer)
- func ShortUUID(u uuid.UUID) string
- func ToContext(ctx context.Context, logger Logger) (context.Context, error)
- type DebugLogger
- type DefaultDebugLogger
- type DefaultErrorLogger
- type DefaultInfoLogger
- type DefaultNoticeLogger
- type DefaultTraceLogger
- type ErrorLogger
- type InfoLogger
- type JSONFormatter
- type LeveledLogger
- func (ll *LeveledLogger) AddDebugLogger(newLogger DebugLogger)
- func (ll *LeveledLogger) AddErrorLogger(newLogger ErrorLogger)
- func (ll *LeveledLogger) AddInfoLogger(newLogger InfoLogger)
- func (ll *LeveledLogger) AddNoticeLogger(newLogger NoticeLogger)
- func (ll *LeveledLogger) AddTraceLogger(newLogger TraceLogger)
- func (ll *LeveledLogger) ClearLevel(level LogLevel)
- func (ll *LeveledLogger) Debug(msg string)
- func (ll *LeveledLogger) Debugf(format string, args ...interface{})
- func (ll *LeveledLogger) EnabledFor(level LogLevel) bool
- func (ll *LeveledLogger) Error(msg string)
- func (ll *LeveledLogger) Errorf(format string, args ...interface{})
- func (ll *LeveledLogger) Info(msg string)
- func (ll *LeveledLogger) Infof(format string, args ...interface{})
- func (ll *LeveledLogger) Level() LogLevel
- func (ll *LeveledLogger) Notice(msg string)
- func (ll *LeveledLogger) Noticef(format string, args ...interface{})
- func (ll *LeveledLogger) SetLevel(newLevel LogLevel)
- func (ll *LeveledLogger) Trace(msg string)
- func (ll *LeveledLogger) Tracef(format string, args ...interface{})
- func (ll *LeveledLogger) WithDebugLogger(newLogger DebugLogger) *LeveledLogger
- func (ll *LeveledLogger) WithErrorLogger(newLogger ErrorLogger) *LeveledLogger
- func (ll *LeveledLogger) WithInfoLogger(newLogger InfoLogger) *LeveledLogger
- func (ll *LeveledLogger) WithJSONOutput() *LeveledLogger
- func (ll *LeveledLogger) WithLogLevel(level LogLevel) *LeveledLogger
- func (ll *LeveledLogger) WithNoticeLogger(newLogger NoticeLogger) *LeveledLogger
- func (ll *LeveledLogger) WithSyslogOutput() *LeveledLogger
- func (ll *LeveledLogger) WithTraceLogger(newLogger TraceLogger) *LeveledLogger
- type LogBuffer
- type LogLevel
- type Logger
- type NoticeLogger
- type Outputter
- type TraceLogger
Constants ¶
const (
DefaultLogLevel = LogLevelInfo
)
Variables ¶
This section is empty.
Functions ¶
func MustCreateSyslogger ¶
MustCreateSyslogger attempts to create a *log.Logger configured for output to the system log daemon. If it fails, it will panic.
func NewTestCommandLineLogger ¶
func NewTestCommandLineLogger() (*LeveledLogger, *LogBuffer)
NewTestCommandlineLogger returns a commandline logger and a *LogBuffer, with the logger configured to send all output into the buffer. The logger's level is set to TRACE by default.
func NewTestLogger ¶
func NewTestLogger(prefix string) (*LeveledLogger, *LogBuffer)
NewTestLogger returns a logger and a *LogBuffer, with the logger configured to send all output into the buffer. The logger's level is set to TRACE by default.
Types ¶
type DebugLogger ¶
type DebugLogger interface {
Debugf(format string, args ...interface{})
}
DebugLogger defines an interface to be implemented by Debug loggers.
type DefaultDebugLogger ¶
type DefaultDebugLogger struct {
// contains filtered or unexported fields
}
DefaultDebugLogger implements the DebugLogger interface.
func NewDebugLogger ¶
func NewDebugLogger(dest io.Writer) *DefaultDebugLogger
NewDebugLogger returns a DebugLogger configured for outputting debugging messages.
func (*DefaultDebugLogger) Debugf ¶
func (l *DefaultDebugLogger) Debugf(format string, args ...interface{})
Debugf emits a formatted debug message.
func (*DefaultDebugLogger) WithJSONOutput ¶
func (l *DefaultDebugLogger) WithJSONOutput() DebugLogger
WithJSONOutput switches the logger's output to use structured JSON formatting.
func (*DefaultDebugLogger) WithSyslogOutput ¶
func (l *DefaultDebugLogger) WithSyslogOutput() DebugLogger
WithSyslogOutput switches the logger's output to emit messages via the system logging service.
type DefaultErrorLogger ¶
type DefaultErrorLogger struct {
// contains filtered or unexported fields
}
DefaultErrorLogger implements the ErrorLogger interface.
func NewCommandLineErrorLogger ¶
func NewCommandLineErrorLogger(output io.Writer) *DefaultErrorLogger
NewCommandLineErrorLogger returns an ErrorLogger configured for outputting unadorned error messages (i.e. no timestamps, source info, etc); typically used for CLI utility logging.
func NewErrorLogger ¶
func NewErrorLogger(prefix string, output io.Writer) *DefaultErrorLogger
NewErrorLogger returns an ErrorLogger configured for outputting error messages with standard formatting (e.g. to stderr, logfile, etc.)
func (*DefaultErrorLogger) Errorf ¶
func (l *DefaultErrorLogger) Errorf(format string, args ...interface{})
Errorf emits a formatted error message.
func (*DefaultErrorLogger) WithJSONOutput ¶
func (l *DefaultErrorLogger) WithJSONOutput() ErrorLogger
WithJSONOutput switches the logger's output to use structured JSON formatting.
func (*DefaultErrorLogger) WithSyslogOutput ¶
func (l *DefaultErrorLogger) WithSyslogOutput() ErrorLogger
WithSyslogOutput switches the logger's output to emit messages via the system logging service.
type DefaultInfoLogger ¶
type DefaultInfoLogger struct {
// contains filtered or unexported fields
}
DefaultInfoLogger implements the InfoLogger interface.
func NewCommandLineInfoLogger ¶
func NewCommandLineInfoLogger(output io.Writer) *DefaultInfoLogger
NewCommandLineInfoLogger returns an InfoLogger configured for outputting unadorned informational messages (i.e. no timestamps, source info, etc); typically used for CLI utility logging.
func NewInfoLogger ¶
func NewInfoLogger(prefix string, output io.Writer) *DefaultInfoLogger
NewInfoLogger returns an InfoLogger configured for outputting informational messages with standard formatting (e.g. to stderr, logfile, etc.)
func (*DefaultInfoLogger) Infof ¶
func (l *DefaultInfoLogger) Infof(format string, args ...interface{})
Infof emits a formatted informational message.
func (*DefaultInfoLogger) WithJSONOutput ¶
func (l *DefaultInfoLogger) WithJSONOutput() InfoLogger
WithJSONOutput switches the logger's output to use structured JSON formatting.
func (*DefaultInfoLogger) WithSyslogOutput ¶
func (l *DefaultInfoLogger) WithSyslogOutput() InfoLogger
WithSyslogOutput switches the logger's output to emit messages via the system logging service.
type DefaultNoticeLogger ¶
type DefaultNoticeLogger struct {
// contains filtered or unexported fields
}
DefaultNoticeLogger implements the NoticeLogger interface.
func NewCommandLineNoticeLogger ¶
func NewCommandLineNoticeLogger(output io.Writer) *DefaultNoticeLogger
NewCommandLineNoticeLogger returns a NoticeLogger configured for outputting unadorned notice messages (i.e. no timestamps, source info, etc); typically used for CLI utility logging.
func NewNoticeLogger ¶
func NewNoticeLogger(prefix string, output io.Writer) *DefaultNoticeLogger
NewNoticeLogger returns NoticeLogger configured for outputting notice messages with standard formatting (e.g. to stderr, logfile, etc.)
func (*DefaultNoticeLogger) Noticef ¶
func (l *DefaultNoticeLogger) Noticef(format string, args ...interface{})
Noticef emits a formatted notice message.
func (*DefaultNoticeLogger) WithJSONOutput ¶
func (l *DefaultNoticeLogger) WithJSONOutput() NoticeLogger
WithJSONOutput switches the logger's output to use structured JSON formatting.
func (*DefaultNoticeLogger) WithSyslogOutput ¶
func (l *DefaultNoticeLogger) WithSyslogOutput() NoticeLogger
WithSyslogOutput switches the logger's output to emit messages via the system logging service.
type DefaultTraceLogger ¶
type DefaultTraceLogger DefaultDebugLogger
DefaultTraceLogger implements the TraceLogger interface by wrapping the DefaultDebugLogger implementation.
func NewTraceLogger ¶
func NewTraceLogger(dest io.Writer) *DefaultTraceLogger
NewTraceLogger returns a DebugLogger configured for outputting trace-level messages.
func (*DefaultTraceLogger) Tracef ¶
func (l *DefaultTraceLogger) Tracef(format string, args ...interface{})
Tracef emits a formatted trace message.
type ErrorLogger ¶
type ErrorLogger interface {
Errorf(format string, args ...interface{})
}
ErrorLogger defines an interface to be implemented by Error loggers.
type InfoLogger ¶
type InfoLogger interface {
Infof(format string, args ...interface{})
}
InfoLogger defines an interface to be implemented by Info loggers.
type JSONFormatter ¶
type JSONFormatter struct {
// contains filtered or unexported fields
}
JSONFormatter emits JSON-formatted log output
func NewJSONFormatter ¶
func NewJSONFormatter(output io.Writer, level, extraData string, flags int) *JSONFormatter
NewJSONFormatter returns a *JSONFormatter configured to emit JSON-formatted output.
type LeveledLogger ¶
LeveledLogger provides a logging implementation which can emit log messages to multiple destinations with different output formats.
func NewCombinedLogger ¶
func NewCombinedLogger(prefix string, output io.Writer) *LeveledLogger
NewCombinedLogger returns a logger configured to send all output to the supplied io.Writer.
func NewCommandLineLogger ¶
func NewCommandLineLogger() *LeveledLogger
NewCommandLineLogger returns a logger configured to send non-error output to stdout and error/debug output to stderr. The output format is suitable for command line utilities which don't want output to include timestamps and filenames.
func NewStdoutLogger ¶
func NewStdoutLogger(prefix string) *LeveledLogger
NewStdoutLogger returns a logger configured to send all output to stdout (suitable for containerized/systemd operation).
func (*LeveledLogger) AddDebugLogger ¶
func (ll *LeveledLogger) AddDebugLogger(newLogger DebugLogger)
AddDebugLogger adds the specified Debug logger to the logger.
func (*LeveledLogger) AddErrorLogger ¶
func (ll *LeveledLogger) AddErrorLogger(newLogger ErrorLogger)
AddErrorLogger adds the specified Error logger to the logger.
func (*LeveledLogger) AddInfoLogger ¶
func (ll *LeveledLogger) AddInfoLogger(newLogger InfoLogger)
AddInfoLogger adds the specified Info logger to the logger.
func (*LeveledLogger) AddNoticeLogger ¶
func (ll *LeveledLogger) AddNoticeLogger(newLogger NoticeLogger)
AddNoticeLogger adds the specified Notice logger to the logger.
func (*LeveledLogger) AddTraceLogger ¶
func (ll *LeveledLogger) AddTraceLogger(newLogger TraceLogger)
AddTraceLogger adds the specified Trace logger to the logger.
func (*LeveledLogger) ClearLevel ¶
func (ll *LeveledLogger) ClearLevel(level LogLevel)
ClearLevel clears all loggers for the specified level.
func (*LeveledLogger) Debug ¶
func (ll *LeveledLogger) Debug(msg string)
Debug emits an unformatted message at Debug level, if the logger is configured to do so.
func (*LeveledLogger) Debugf ¶
func (ll *LeveledLogger) Debugf(format string, args ...interface{})
Debugf emits a formatted message at Debug level, if the logger is configured to do so.
func (*LeveledLogger) EnabledFor ¶
func (ll *LeveledLogger) EnabledFor(level LogLevel) bool
EnabledFor returns true if the logger is enabled for the specified LogLevel.
func (*LeveledLogger) Error ¶
func (ll *LeveledLogger) Error(msg string)
Error emits an unformatted message at Error level, if the logger is configured to do so.
func (*LeveledLogger) Errorf ¶
func (ll *LeveledLogger) Errorf(format string, args ...interface{})
Errorf emits a formatted message at Error level, if the logger is configured to do so.
func (*LeveledLogger) Info ¶
func (ll *LeveledLogger) Info(msg string)
Info emits an unformatted message at Info level, if the logger is configured to do so.
func (*LeveledLogger) Infof ¶
func (ll *LeveledLogger) Infof(format string, args ...interface{})
Infof emits a formatted message at Info level, if the logger is configured to do so.
func (*LeveledLogger) Level ¶
func (ll *LeveledLogger) Level() LogLevel
Level returns the logger's current LogLevel.
func (*LeveledLogger) Notice ¶
func (ll *LeveledLogger) Notice(msg string)
Notice emits an unformatted message at Notice level, if the logger is configured to do so.
func (*LeveledLogger) Noticef ¶
func (ll *LeveledLogger) Noticef(format string, args ...interface{})
Noticef emits a formatted message at Notice level, if the logger is configured to do so.
func (*LeveledLogger) SetLevel ¶
func (ll *LeveledLogger) SetLevel(newLevel LogLevel)
SetLevel sets the logger's LogLevel, at or above which messages will be emitted.
func (*LeveledLogger) Trace ¶
func (ll *LeveledLogger) Trace(msg string)
Trace emits an unformatted message at Trace level, if the logger is configured to do so.
func (*LeveledLogger) Tracef ¶
func (ll *LeveledLogger) Tracef(format string, args ...interface{})
Tracef emits a formatted message at Trace level, if the logger is configured to do so.
func (*LeveledLogger) WithDebugLogger ¶
func (ll *LeveledLogger) WithDebugLogger(newLogger DebugLogger) *LeveledLogger
WithDebugLogger adds the specified Debug logger to the logger as part of a chained method call.
func (*LeveledLogger) WithErrorLogger ¶
func (ll *LeveledLogger) WithErrorLogger(newLogger ErrorLogger) *LeveledLogger
WithErrorLogger adds the specified Error logger to the logger as part of a chained method call.
func (*LeveledLogger) WithInfoLogger ¶
func (ll *LeveledLogger) WithInfoLogger(newLogger InfoLogger) *LeveledLogger
WithInfoLogger adds the specified Info logger to the logger as part of a chained method call.
func (*LeveledLogger) WithJSONOutput ¶
func (ll *LeveledLogger) WithJSONOutput() *LeveledLogger
WithJSONOutput is a convenience method to set all logging outputs to the JSON formatter.
func (*LeveledLogger) WithLogLevel ¶
func (ll *LeveledLogger) WithLogLevel(level LogLevel) *LeveledLogger
WithLogLevel allows the logger's LogLevel to be set as part of a chained method call.
func (*LeveledLogger) WithNoticeLogger ¶
func (ll *LeveledLogger) WithNoticeLogger(newLogger NoticeLogger) *LeveledLogger
WithNoticeLogger adds the specified Notice logger to the logger as part of a chained method call.
func (*LeveledLogger) WithSyslogOutput ¶
func (ll *LeveledLogger) WithSyslogOutput() *LeveledLogger
WithSyslogOutput is a convenience method to set all logging outputs to the Syslog formatter.
func (*LeveledLogger) WithTraceLogger ¶
func (ll *LeveledLogger) WithTraceLogger(newLogger TraceLogger) *LeveledLogger
WithTraceLogger adds the specified Trace logger to the logger as part of a chained method call.
type LogBuffer ¶
LogBuffer provides a thread-safe wrapper for bytes.Buffer. It only wraps a subset of bytes.Buffer's methods; just enough to implement io.Reader, io.Writer, and fmt.Stringer. The Reset() method is also wrapped in order to make it useful for testing.
type LogLevel ¶
type LogLevel int32
LogLevel represents the level at which the logger will emit log messages
const ( // LogLevelDisabled disables any logging output LogLevelDisabled LogLevel = iota // LogLevelError emits messages at ERROR or higher LogLevelError // LogLevelNotice emits messages at NOTICE or higher LogLevelNotice // LogLevelInfo emits messages at INFO or higher LogLevelInfo // LogLevelDebug emits messages at DEBUG or higher LogLevelDebug // LogLevelTrace emits messages at TRACE or higher LogLevelTrace )
type Logger ¶
type Logger interface { EnabledFor(level LogLevel) bool TraceLogger Trace(msg string) DebugLogger Debug(msg string) InfoLogger Info(msg string) NoticeLogger Notice(msg string) ErrorLogger Error(msg string) }
Logger defines a standard logging interface
func FromContext ¶
FromContext returns the logger from the context, or a no-op logger if no logger is present.
type NoticeLogger ¶
type NoticeLogger interface {
Noticef(format string, args ...interface{})
}
NoticeLogger defines an interface to be implemented by Notice loggers.
type TraceLogger ¶
type TraceLogger interface {
Tracef(format string, args ...interface{})
}
TraceLogger defines an interface to be implemented by Trace loggers.