Documentation ¶
Overview ¶
Package log provides a wrapped zap logger interface for microservices to use, and also a simple Wrapper interface to be used by other baseplate.go packages.
Index ¶
- Constants
- func CapitalLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func DPanic(args ...interface{})
- func DPanicf(template string, args ...interface{})
- func DPanicw(msg string, keysAndValues ...interface{})
- func Debug(args ...interface{})
- func Debugf(template string, args ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func Error(args ...interface{})
- func ErrorWithRaven(msg string, err error, keysAndValues ...interface{})
- func Errorf(template string, args ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(template string, args ...interface{})
- func Fatalw(msg string, keysAndValues ...interface{})
- func FullCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- func Info(args ...interface{})
- func Infof(template string, args ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func InitLogger(logLevel Level)
- func InitLoggerWithConfig(logLevel Level, cfg zap.Config)
- func NopWrapper(msg string)
- func Panic(args ...interface{})
- func Panicf(template string, args ...interface{})
- func Panicw(msg string, keysAndValues ...interface{})
- func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- func StringToAtomicLevel(loglevel Level) zapcore.Level
- func Sync() error
- func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Warn(args ...interface{})
- func Warnf(template string, args ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- func With(args ...interface{}) *zap.SugaredLogger
- type KitWrapper
- type Level
- type Wrapper
Constants ¶
const RFC3339Nano = "ts=2006-01-02T15:04:05.000000Z"
RFC3339Nano is a time format for TimeEncoder
Variables ¶
This section is empty.
Functions ¶
func CapitalLevelEncoder ¶
func CapitalLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
CapitalLevelEncoder adds logger level in uppercase
func DPanic ¶
func DPanic(args ...interface{})
DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)
func DPanicf ¶
func DPanicf(template string, args ...interface{})
DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)
func DPanicw ¶
func DPanicw(msg string, keysAndValues ...interface{})
DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.
func Debugf ¶
func Debugf(template string, args ...interface{})
Debugf uses fmt.Sprintf to log a templated message.
func Debugw ¶
func Debugw(msg string, keysAndValues ...interface{})
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).Debug(msg)
func ErrorWithRaven ¶
ErrorWithRaven logs a message with some additional context, then sends the error to Sentry. The variadic key-value pairs are treated as they are in With.
func Errorf ¶
func Errorf(template string, args ...interface{})
Errorf uses fmt.Sprintf to log a templated message.
func Errorw ¶
func Errorw(msg string, keysAndValues ...interface{})
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Fatal ¶
func Fatal(args ...interface{})
Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.
func Fatalf ¶
func Fatalf(template string, args ...interface{})
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func Fatalw ¶
func Fatalw(msg string, keysAndValues ...interface{})
Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.
func FullCallerEncoder ¶
func FullCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
FullCallerEncoder serializes a caller in /full/path/to/package/file:line format.
func Infof ¶
func Infof(template string, args ...interface{})
Infof uses fmt.Sprintf to log a templated message.
func Infow ¶
func Infow(msg string, keysAndValues ...interface{})
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func InitLogger ¶
func InitLogger(logLevel Level)
InitLogger provides a quick way to start or replace a logger Pass in debug as log level enables development mode (which makes DPanicLevel logs panic).
func InitLoggerWithConfig ¶
InitLoggerWithConfig provides a quick way to start or replace a logger Pass in debug as log level enables development mode (which makes DPanicLevel logs panic). Pass in a cfg to provide a logger with custom setting
func NopWrapper ¶
func NopWrapper(msg string)
NopWrapper is a Wrapper implementation that does nothing.
func Panic ¶
func Panic(args ...interface{})
Panic uses fmt.Sprint to construct and log a message, then panics.
func Panicf ¶
func Panicf(template string, args ...interface{})
Panicf uses fmt.Sprintf to log a templated message, then panics.
func Panicw ¶
func Panicw(msg string, keysAndValues ...interface{})
Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.
func ShortCallerEncoder ¶
func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
ShortCallerEncoder serializes a caller in package/file:line format, trimming all but the final directory from the full path.
func StringToAtomicLevel ¶
StringToAtomicLevel converts in to a zap acceptable atomic level struct
func TimeEncoder ¶
func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
TimeEncoder is customized to add ts in the front
func Warnf ¶
func Warnf(template string, args ...interface{})
Warnf uses fmt.Sprintf to log a templated message.
func Warnw ¶
func Warnw(msg string, keysAndValues ...interface{})
Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func With ¶
func With(args ...interface{}) *zap.SugaredLogger
With wraps around the underline logger's With
Types ¶
type KitWrapper ¶
KitWrapper is a type that implements go-kit/log.Logger interface with zap logger.
func KitLogger ¶
func KitLogger(level Level) KitWrapper
KitLogger returns a go-kit compatible logger.
func (KitWrapper) Log ¶
func (w KitWrapper) Log(keyvals ...interface{}) error
Log implements go-kit/log.Logger interface.
type Level ¶
type Level string
Level is the verbose representation of log level
const ( NopLevel Level = "nop" DebugLevel Level = "debug" InfoLevel Level = "info" WarnLevel Level = "warn" ErrorLevel Level = "error" PanicLevel Level = "panic" FatalLevel Level = "fatal" // This will have the same effect as nop but slower ZapNopLevel zapcore.Level = zapcore.FatalLevel + 1 )
Enums for Level
type Wrapper ¶
type Wrapper func(msg string)
Wrapper is a simple wrapper of a logging function.
In reality we might actually use different logging libraries in different services, and they are not always compatible with each other. Wrapper is a simple common ground that it's easy to wrap whatever logging library we use into.
This is also the same type as thrift.Logger and can be used interchangeably (sometimes with a typecast).
func StdWrapper ¶
StdWrapper wraps stdlib log package into a Wrapper.
func TestWrapper ¶
TestWrapper is a wrapper can be used in test codes.
It fails the test when called.
func ZapWrapper ¶
ZapWrapper wraps zap log package into a Wrapper.