log

package
v0.0.0-...-bde19ca Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

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

View Source
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 Debug

func Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

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 Error

func Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func ErrorWithRaven

func ErrorWithRaven(msg string, err error, keysAndValues ...interface{})

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 Info

func Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

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

func InitLoggerWithConfig(logLevel Level, cfg zap.Config)

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

func StringToAtomicLevel(loglevel Level) zapcore.Level

StringToAtomicLevel converts in to a zap acceptable atomic level struct

func Sync

func Sync() error

Sync flushes any buffered log entries.

func TimeEncoder

func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

TimeEncoder is customized to add ts in the front

func Warn

func Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

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

type KitWrapper zapcore.Level

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

func StdWrapper(logger *stdlog.Logger) Wrapper

StdWrapper wraps stdlib log package into a Wrapper.

func TestWrapper

func TestWrapper(tb testing.TB) Wrapper

TestWrapper is a wrapper can be used in test codes.

It fails the test when called.

func ZapWrapper

func ZapWrapper(level Level) Wrapper

ZapWrapper wraps zap log package into a Wrapper.

Jump to

Keyboard shortcuts

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