Documentation ¶
Index ¶
- func IndentAndQuoteLines(buffer, indent string) string
- func IndentLines(buffer, indent string) string
- func LogLines(logger Printer, buffer, indent string)
- func PrintEvent(ev *Event, log Logger)
- func SetCtx(ctx context.Context, l Logger) context.Context
- type Accumulator
- func (dl *Accumulator) Add(prio Priority, format string, args ...interface{})
- func (dl *Accumulator) Debugf(format string, args ...interface{})
- func (dl *Accumulator) Errorf(format string, args ...interface{})
- func (dl *Accumulator) Forward(log Logger)
- func (dl *Accumulator) ForwardWithPrinter(log Logger, printer func(*Event, Logger))
- func (dl *Accumulator) Infof(format string, args ...interface{})
- func (dl *Accumulator) Retrieve() []Event
- func (dl *Accumulator) SetOutput(writer io.Writer)
- func (dl *Accumulator) Warnf(format string, args ...interface{})
- type DefaultLogger
- func (dl DefaultLogger) Debugf(format string, args ...interface{})
- func (dl DefaultLogger) Errorf(format string, args ...interface{})
- func (dl DefaultLogger) Infof(format string, args ...interface{})
- func (dl DefaultLogger) Printf(format string, args ...interface{})
- func (dl DefaultLogger) SetOutput(output io.Writer)
- func (dl DefaultLogger) Warnf(format string, args ...interface{})
- type Event
- type Forwardable
- type IndentedError
- type Logger
- type NilLogger
- func (dl NilLogger) Debugf(format string, args ...interface{})
- func (dl NilLogger) Errorf(format string, args ...interface{})
- func (dl NilLogger) Infof(format string, args ...interface{})
- func (dl NilLogger) Printf(format string, args ...interface{})
- func (dl NilLogger) SetOutput(output io.Writer)
- func (dl NilLogger) Warnf(format string, args ...interface{})
- type Printer
- type Priority
- type Proxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IndentAndQuoteLines ¶
Just like IndentLines, but converts all non-space / non-ascii printable characters to \xHH sequences.
func IndentLines ¶
IndentLines indents each line in the buffer with the specified string.
func LogLines ¶
LogLines breaks a buffer into lines and logs each one of them with the specified indentation and printer.
func PrintEvent ¶
Types ¶
type Accumulator ¶
type Accumulator struct {
// contains filtered or unexported fields
}
Accumulator is a thread safe object implementing the Logger interface that accumulates all messages being logged.
You can then use the Retrieve() or Forward() methods to access or print the accumulated messages.
func NewAccumulator ¶
func NewAccumulator() *Accumulator
func (*Accumulator) Add ¶
func (dl *Accumulator) Add(prio Priority, format string, args ...interface{})
func (*Accumulator) Debugf ¶
func (dl *Accumulator) Debugf(format string, args ...interface{})
func (*Accumulator) Errorf ¶
func (dl *Accumulator) Errorf(format string, args ...interface{})
func (*Accumulator) Forward ¶
func (dl *Accumulator) Forward(log Logger)
func (*Accumulator) ForwardWithPrinter ¶
func (dl *Accumulator) ForwardWithPrinter(log Logger, printer func(*Event, Logger))
func (*Accumulator) Infof ¶
func (dl *Accumulator) Infof(format string, args ...interface{})
func (*Accumulator) Retrieve ¶
func (dl *Accumulator) Retrieve() []Event
func (*Accumulator) SetOutput ¶
func (dl *Accumulator) SetOutput(writer io.Writer)
func (*Accumulator) Warnf ¶
func (dl *Accumulator) Warnf(format string, args ...interface{})
type DefaultLogger ¶
DefaultLogger uses a single Printf to implement the Logger interface.
Printer must be provided. Use log.Printf to rely on default golang logging, with:
logger := &DefaultLoger{Printer: log.Printf}
... or just use the pre-defined `Go` variable bleow for default Go logging.
func (DefaultLogger) Debugf ¶
func (dl DefaultLogger) Debugf(format string, args ...interface{})
func (DefaultLogger) Errorf ¶
func (dl DefaultLogger) Errorf(format string, args ...interface{})
func (DefaultLogger) Infof ¶
func (dl DefaultLogger) Infof(format string, args ...interface{})
func (DefaultLogger) Printf ¶
func (dl DefaultLogger) Printf(format string, args ...interface{})
func (DefaultLogger) SetOutput ¶
func (dl DefaultLogger) SetOutput(output io.Writer)
func (DefaultLogger) Warnf ¶
func (dl DefaultLogger) Warnf(format string, args ...interface{})
type Forwardable ¶
type Forwardable interface {
Forward(Logger)
}
Forwardable is the interface implemented by any logger capable of forwarding, upon request, buffered messages to another logger.
type IndentedError ¶
type IndentedError struct {
// contains filtered or unexported fields
}
IndentedError reformats the error to have indented new lines.
func NewIndentedError ¶
func NewIndentedError(err error, indent string) *IndentedError
NewIndentedError wraps an error into an object that ensures that when the error is converted to a string and printed, via the Error method, every line of the error message is indented with indent.
For example, let's say you have an error err that converted with fmt.Printf(... %s ...) leads to the following output:
An error occured in executing function, stack trace follows. Function1() ... Function2() ...
Using NewIndentedError(err, "| "), would lead to:
| An error occured in executing function, stack trace follows. | Function1() ... | Function2() ...
Further, the error returned by NewIntendedError implements the Unwrap interface, allowing programmatic access to the original error.
func (*IndentedError) Error ¶
func (ie *IndentedError) Error() string
func (*IndentedError) Unwrap ¶
func (ie *IndentedError) Unwrap() error
type Logger ¶
type Logger interface { // Use for messages that are pretty much only useful when debugging // specific behaviors. Should be used rarely. // Expect debug messages to be discarded. Debugf(format string, args ...interface{}) // Use for messages that clearly a) outline a problem that b) the operator MUST act upon. // Errors are generally reserved for things that cause the program to fail and must be fixed. Errorf(format string, args ...interface{}) // Use for messages that a) outline a problem that b) is actionable, and c) the operator // may want to act upon - even though the program may have recovered or continued without // intervention (in degraded mode, or without some functionality, ...). Warnf(format string, args ...interface{}) // Use for messages that are either not actionable, or require no action by the operator. Infof(format string, args ...interface{}) SetOutput(writer io.Writer) }
Logger is the interface used by the enkit libraries to log messages.
The logrus library can be used out of the box without additional glue. The golang log library is used by default, through DefaultLogger. DefaultLogger can be used to pass an arbitrary log function as well.
var Go Logger = &DefaultLogger{Printer: log.Printf}
Go is a pre-defined logger that will log using default log library.
Nil is a pre-defined logger that will discard all the output.
Replacing the Nil global with something else can allow seeing log messages that would normally be discarded.
type NilLogger ¶
type NilLogger struct{}
NilLogger is a logger that discards all messages.
Prefer using logger.Nil to instantiating your copy of &NilLogger{}.
type Printer ¶
type Printer func(format string, args ...interface{})
Printer is a Printf like function.
type Priority ¶
type Priority int
Represents a logging priority. Logging priorities map to the Debugf, Infof, Warnf, and Errorf printers.