log

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContext added in v0.1.0

func AddContext(ctx context.Context, fields ...interface{}) context.Context

AddContext adds fields to the context that can be used in WithContext.

func Debug

func Debug(args ...interface{})

Debug logs a message. This is a convinience function for logger.Debug().

func Debugf

func Debugf(template string, args ...interface{})

Debugf logs a templated message. This is a convinience function for logger.Debugf().

func Error

func Error(args ...interface{})

Error logs a message. This is a convinience function for logger.Error().

func Errorf

func Errorf(template string, args ...interface{})

Errorf logs a templated message. This is a convinience function for logger.Errorf().

func Info

func Info(args ...interface{})

Info logs a message. This is a convinience function for logger.Info().

func Infof

func Infof(template string, args ...interface{})

Infof logs a templated message. This is a convinience function for logger.Infof().

func Init

func Init(c *Configuration)

Init initializes the global logger with provided level.

Default level is zapcore.InfoLevel and non-development.

Types

type Configuration added in v0.0.27

type Configuration struct {
	Level       Level
	Development bool
}

Configuration represents a log configuration.

func RegisterFlags added in v0.0.27

func RegisterFlags(cmd *cobra.Command) *Configuration

RegisterFlags registers logging configuration flags on command cmd and returns pointers to the values.

func (*Configuration) ParseFromEnvironmnet added in v0.0.27

func (c *Configuration) ParseFromEnvironmnet()

ParseFromEnvironmnet parses configuration from the environment and writes found values to configuration struct c.

type Level added in v0.0.27

type Level struct {
	zapcore.Level
}

Level is a wrapped zapcore.Level that implements the pflag.Value interface.

func (*Level) Type added in v0.0.27

func (*Level) Type() string

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a general structured logger.

func New added in v0.1.0

func New(c *Configuration) *Logger

New allocates and returns a Logger instance.

func With

func With(args ...interface{}) *Logger

With returns a logger with custom structured fields added to the root of the log entries. The arguments are passed to the underlying sugared zap logger. See the zap documentation for details. If an argument is a zap.Field it is logged accordingly, otherwise the arguments are treated as key value pairs.

For example,

 zlog.With(
   "hello", "world",
   zap.String("zapKey", "zapValue"),
   "user", User{Name: "alice"},
).Info("msg")

logs the following fields (some fields omitted)

{ "message": "msg", "hello": "world", "zapKey": "zapValue", "user": { "name": "alice" }}

func WithContext added in v0.1.0

func WithContext(ctx context.Context) *Logger

WithContext returns a Logger instance. Every logged line with the returned logger will contain the extracted fields (if any) from the context.

func WithFields

func WithFields(args ...interface{}) *Logger

WithFields returns a logger with custom structured fields added to the 'fields' key in the log entries. The arguments are passed to the underlying sugared zap logger. See the zap documentation for details. If an argument is a zap.Field it is logged accordingly, otherwise the arguments are treated as key value pairs.

For example,

 zlog.WithFields(
   "hello", "world",
   zap.String("zapKey", "zapValue"),
   "user", User{Name: "alice"},
).Info("msg")

logs the following fields (some fields omitted)

{ "message": "msg", "fields": { "hello": "world", "zapKey": "zapValue", "user": { "name": "alice" }}}

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

Debug logs a message.

func (*Logger) Debugf

func (l *Logger) Debugf(template string, args ...interface{})

Debugf logs a templated message.

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

Error logs a message.

func (*Logger) Errorf

func (l *Logger) Errorf(template string, args ...interface{})

Errorf logs a templated message.

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

Info logs a message.

func (*Logger) Infof

func (l *Logger) Infof(template string, args ...interface{})

Infof logs a templated message.

func (*Logger) With added in v0.1.0

func (l *Logger) With(args ...interface{}) *Logger

With returns a logger with custom structured fields added to the root of the log entries. The arguments are passed to the underlying sugared zap logger. See the zap documentation for details. If an argument is a zap.Field it is logged accordingly, otherwise the arguments are treated as key value pairs.

For example,

log.With("hello", "world").With(zap.String("zapKey", "zapValue")).Info("msg")

logs the following fields (some fields omitted)

{ "message": "msg", "hello": "world", "zapKey": "zapValue"}

func (*Logger) WithContext added in v0.1.0

func (l *Logger) WithContext(ctx context.Context) *Logger

WithContext returns a Logger instance. Every logged line with the returned logger will contain the extracted fields (if any) from the context.

func (*Logger) WithFields added in v0.1.0

func (l *Logger) WithFields(args ...interface{}) *Logger

WithFields returns a logger with custom structured fields added to the 'fields' key in the log entries. The arguments are passed to the underlying sugared zap logger. See the zap documentation for details. If an argument is a zap.Field it is logged accordingly, otherwise the arguments are treated as key value pairs.

For example,

log.WithFields("hello", "world").WithFields(zap.String("zapKey", "zapValue")).Info("msg")

logs the following fields (some fields omitted)

{ "message": "msg", "fields": { "hello": "world", "zapKey": "zapValue" }}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL