Documentation ¶
Index ¶
- func ZapContextWithFields(ctx context.Context, fields ...zap.Field) context.Context
- type Logger
- type Logrus
- func (l *Logrus) Debug(msg string, args ...interface{})
- func (l *Logrus) Entry(args ...interface{}) *logrus.Entry
- func (l *Logrus) Error(msg string, args ...interface{})
- func (l *Logrus) Fatal(msg string, args ...interface{})
- func (l *Logrus) Info(msg string, args ...interface{})
- func (l *Logrus) Level() string
- func (l *Logrus) Warn(msg string, args ...interface{})
- func (l *Logrus) Writer() io.Writer
- type Noop
- func (n *Noop) Debug(msg string, args ...interface{})
- func (n *Noop) Error(msg string, args ...interface{})
- func (n *Noop) Fatal(msg string, args ...interface{})
- func (n *Noop) Info(msg string, args ...interface{})
- func (n *Noop) Level() string
- func (n *Noop) Warn(msg string, args ...interface{})
- func (n *Noop) Writer() io.Writer
- type Option
- type Zap
- func (z Zap) Debug(msg string, args ...interface{})
- func (z Zap) Error(msg string, args ...interface{})
- func (z Zap) Fatal(msg string, args ...interface{})
- func (z Zap) GetInternalZapLogger() *zap.SugaredLogger
- func (z Zap) Info(msg string, args ...interface{})
- func (z Zap) Level() string
- func (z Zap) NewContext(ctx context.Context) context.Context
- func (z Zap) Warn(msg string, args ...interface{})
- func (z Zap) Writer() io.Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Logger ¶
type Logger interface { // Debug level message with alternating key/value pairs // key should be string, value could be anything printable Debug(msg string, args ...interface{}) // Info level message with alternating key/value pairs // key should be string, value could be anything printable Info(msg string, args ...interface{}) // Warn level message with alternating key/value pairs // key should be string, value could be anything printable Warn(msg string, args ...interface{}) // Error level message with alternating key/value pairs // key should be string, value could be anything printable Error(msg string, args ...interface{}) // Fatal level message with alternating key/value pairs // key should be string, value could be anything printable Fatal(msg string, args ...interface{}) // Level returns priority level for which this logger will filter logs Level() string // Writer used to print logs Writer() io.Writer }
Logger is a convenient interface to use provided loggers either use it as it is or implement your own interface where the logging implementations are used Each log method must take first string as message and then one or more key,value arguments. For example:
timeTaken := time.Duration(time.Second * 1) l.Debug("processed request", "time taken", timeTaken)
here key should always be a `string` and value could be of any type as long as it is printable.
l.Info("processed request", "time taken", timeTaken, "started at", startedAt)
type Logrus ¶
type Logrus struct {
// contains filtered or unexported fields
}
type Noop ¶
type Noop struct{}
type Option ¶
type Option func(interface{})
Option modifies the logger behavior
func LogrusWithFormatter ¶
LogrusWithFormatter can be used to change default formatting by implementing logrus.Formatter For example:
type PlainFormatter struct{} func (p *PlainFormatter) Format(entry *logrus.Entry) ([]byte, error) { return []byte(entry.Message), nil } l := log.NewLogrus(log.LogrusWithFormatter(&PlainFormatter{}))
func LogrusWithLevel ¶
func LogrusWithWriter ¶
func ZapWithNoop ¶
func ZapWithNoop() Option
type Zap ¶
type Zap struct {
// contains filtered or unexported fields
}
func ZapFromContext ¶ added in v0.2.1
ZapFromContext will help in fetching back zap logger from context
func (Zap) GetInternalZapLogger ¶
func (z Zap) GetInternalZapLogger() *zap.SugaredLogger
GetInternalZapLogger Gets internal SugaredLogger instance
func (Zap) NewContext ¶
NewContext will add Zap inside context