Documentation ¶
Overview ¶
Package log provides a generic interface around loggers.
The log package must be used in conjunction with a logger in contrib package.
Index ¶
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Printf(format string, args ...interface{})
- func Set(logger Logger)
- func ToContext(ctx context.Context) context.Context
- func Trace(args ...interface{})
- func Tracef(format string, args ...interface{})
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- type Fields
- type Logger
- type Noop
- func (n Noop) Debug(args ...interface{})
- func (n Noop) Debugf(format string, args ...interface{})
- func (n Noop) Error(args ...interface{})
- func (n Noop) Errorf(format string, args ...interface{})
- func (n Noop) Fatal(args ...interface{})
- func (n Noop) Fatalf(format string, args ...interface{})
- func (n Noop) Fields() Fields
- func (n Noop) FromContext(ctx context.Context) Logger
- func (n Noop) Info(args ...interface{})
- func (n Noop) Infof(format string, args ...interface{})
- func (n Noop) Output() io.Writer
- func (n Noop) Panic(args ...interface{})
- func (n Noop) Panicf(format string, args ...interface{})
- func (n Noop) Printf(format string, args ...interface{})
- func (n Noop) ToContext(ctx context.Context) context.Context
- func (n Noop) Trace(args ...interface{})
- func (n Noop) Tracef(format string, args ...interface{})
- func (n Noop) Warn(args ...interface{})
- func (n Noop) Warnf(format string, args ...interface{})
- func (n Noop) WithError(err error) Logger
- func (n Noop) WithField(key string, value interface{}) Logger
- func (n Noop) WithFields(keyValues map[string]interface{}) Logger
- func (n Noop) WithTypeOf(obj interface{}) Logger
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs a templated message at debug level.
For templating details see implementation doc.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs a templated message at error level.
For templating details see implementation doc.
func Fatal ¶
func Fatal(args ...interface{})
Fatal is equivalent to Print() followed by a call to os.Exit(1).
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs a templated message at info level.
For templating details see implementation doc.
func Panic ¶
func Panic(args ...interface{})
Panic is equivalent to Print() followed by a call to panic().
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf is equivalent to Printf() followed by a call to panic().
func Printf ¶
func Printf(format string, args ...interface{})
Printf logs a templated message.
For templating details see implementation doc.
func ToContext ¶
Example ¶
Output: level=info msg="foo method." foo_field=example main_field=example level=info msg="bar method." bar_field=example foo_field=example main_field=example level=info msg="withoutContext method" main_field=example
Types ¶
type Fields ¶
type Fields map[string]interface{}
Fields to pass when we want to call WithFields for structured logging.
type Logger ¶
type Logger interface { Printf(format string, args ...interface{}) Tracef(format string, args ...interface{}) Trace(args ...interface{}) Debugf(format string, args ...interface{}) Debug(args ...interface{}) Infof(format string, args ...interface{}) Info(args ...interface{}) Warnf(format string, args ...interface{}) Warn(args ...interface{}) Errorf(format string, args ...interface{}) Error(args ...interface{}) Fatalf(format string, args ...interface{}) Fatal(args ...interface{}) Panicf(format string, args ...interface{}) Panic(args ...interface{}) WithFields(keyValues map[string]interface{}) Logger WithField(key string, value interface{}) Logger WithError(err error) Logger WithTypeOf(obj interface{}) Logger ToContext(ctx context.Context) context.Context FromContext(ctx context.Context) Logger Output() io.Writer Fields() Fields }
Logger is our contract for the logger.
func FromContext ¶
FromContext calls concrete Logger.FromContext().
Example ¶
Output: level=info msg="foo method." foo_field=example main_field=example level=info msg="bar method." bar_field=example foo_field=example main_field=example level=info msg="withoutContext method" main_field=example
func WithFields ¶
WithFields adds fields to logger.
func WithTypeOf ¶
func WithTypeOf(obj interface{}) Logger
WithTypeOf adds type information to logger.
type Noop ¶
type Noop struct{}
Noop is a dummy implementation of Logger