Documentation ¶
Index ¶
- func AddContext(ctx context.Context, fields ...interface{}) context.Context
- func Debug(args ...interface{})
- func Debugf(template string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(template string, args ...interface{})
- func Info(args ...interface{})
- func Infof(template string, args ...interface{})
- func Init(c *Configuration)
- type Configuration
- type Level
- type Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(template string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(template string, args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(template string, args ...interface{})
- func (l *Logger) With(args ...interface{}) *Logger
- func (l *Logger) WithContext(ctx context.Context) *Logger
- func (l *Logger) WithFields(args ...interface{}) *Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddContext ¶ added in v0.1.0
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
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
Level is a wrapped zapcore.Level that implements the pflag.Value interface.
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
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) With ¶ added in v0.1.0
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
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
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" }}