Documentation ¶
Overview ¶
Package logging provides the standard logging mechanism for Tast.
Index ¶
- func AttachLogger(ctx context.Context, logger Logger) context.Context
- func AttachLoggerNoPropagation(ctx context.Context, logger Logger) context.Context
- func Debug(ctx context.Context, args ...interface{})
- func Debugf(ctx context.Context, format string, args ...interface{})
- func HasLogger(ctx context.Context) bool
- func Info(ctx context.Context, args ...interface{})
- func Infof(ctx context.Context, format string, args ...interface{})
- type FuncSink
- type Level
- type Logger
- type MultiLogger
- type Sink
- type SinkLogger
- type SyslogLogger
- type WriterSink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachLogger ¶
AttachLogger creates a new context with logger attached. Logs emitted via the new context are propagated to the parent context.
func AttachLoggerNoPropagation ¶
AttachLoggerNoPropagation creates a new context with logger attached. In contrast to AttachLogger, logs emitted via the new context are not propagated to the parent context.
Types ¶
type FuncSink ¶
type FuncSink struct {
// contains filtered or unexported fields
}
FuncSink is a Sink that calls a function.
All calls to the underlying function are synchronized.
func NewFuncSink ¶
NewFuncSink creates a new FuncSink from a function.
type Level ¶
type Level int
Level indicates a logging level. A larger level value means a log is more important.
type Logger ¶
type Logger interface { // Log gets called for a log entry. Log(level Level, ts time.Time, msg string) }
Logger defines the interface for loggers that consume logs sent via context.Context.
You can create a new context with a Logger attached by AttachLogger. The attached logger will consume all logs sent to the context, as well as those logs sent to its descendant contexts as long as you don't attach another logger to a descendant context with no propagation. See AttachLogger for more details.
type MultiLogger ¶
type MultiLogger struct {
// contains filtered or unexported fields
}
MultiLogger is a Logger that copies logs to multiple underlying loggers. A logger can be added and removed from MultiLogger at any time.
func NewMultiLogger ¶
func NewMultiLogger(loggers ...Logger) *MultiLogger
NewMultiLogger creates a new MultiLogger with a specified initial set of underlying loggers.
func (*MultiLogger) AddLogger ¶
func (ml *MultiLogger) AddLogger(logger Logger)
AddLogger adds a logger to the set of underlying loggers.
func (*MultiLogger) Log ¶
func (ml *MultiLogger) Log(level Level, ts time.Time, msg string)
Log copies a log to the current underlying loggers.
func (*MultiLogger) RemoveLogger ¶
func (ml *MultiLogger) RemoveLogger(logger Logger)
RemoveLogger removes a logger from the set of underlying loggers.
type Sink ¶
type Sink interface { // Log gets called for a log entry. Log(msg string) }
Sink represents a destination of logs, e.g. a log file or console.
type SinkLogger ¶
type SinkLogger struct {
// contains filtered or unexported fields
}
SinkLogger is a Logger that processes logs by a Sink.
func NewSinkLogger ¶
func NewSinkLogger(level Level, timestamp bool, sink Sink) *SinkLogger
NewSinkLogger creates a new SinkLogger.
level specifies the minimum level of logs the sink should get notified of. If timestamp is true, a timestamp is prepended to a log before it is sent to the sink.
type SyslogLogger ¶
type SyslogLogger struct {
// contains filtered or unexported fields
}
SyslogLogger is a Logger that routes logs to syslog.
func NewSyslogLogger ¶
func NewSyslogLogger() (*SyslogLogger, error)
NewSyslogLogger creates a new SyslogLogger. It returns an error if it fails to connect to the syslog endpoint.
func (*SyslogLogger) Close ¶
func (l *SyslogLogger) Close() error
Close closes the underlying connection to the syslog endpoint.
type WriterSink ¶
type WriterSink struct {
// contains filtered or unexported fields
}
WriterSink is a Sink that writes logs to io.Writer.
All writes to io.Writer are synchronized.
func NewWriterSink ¶
func NewWriterSink(w io.Writer) *WriterSink
NewWriterSink creates a new WriterSink from io.Writer.
func (*WriterSink) Log ¶
func (s *WriterSink) Log(msg string)
Log writes a log to the underlying io.Writer.
Directories ¶
Path | Synopsis |
---|---|
Package loggingtest provides logging utilities for unit tests.
|
Package loggingtest provides logging utilities for unit tests. |