log

package module
v0.0.0-...-29c6640 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2019 License: MIT Imports: 10 Imported by: 0

README

log

A logging library for Go programs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTimeFormat is the default time format used in logging
	DefaultTimeFormat = "2006-01-02 15:04:05.000 -0700"
)

Functions

func Debug

func Debug(msg string, fields ...zap.Field)

Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func DefaultTimeEncoder

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

DefaultTimeEncoder serializes time.Time to a human-readable formatted string

func Error

func Error(msg string, fields ...zap.Field)

Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func Fatal

func Fatal(msg string, fields ...zap.Field)

Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func Ginzap

func Ginzap(logger *zap.Logger) gin.HandlerFunc

Ginzap returns a gin.HandlerFunc (middleware) that logs requests using uber-go/zap.

Requests with errors are logged using zap.Error(). Requests without errors are logged using zap.Info().

It receives:

  1. A time package format string (e.g. time.RFC3339).
  2. A boolean stating whether to use UTC time zone or local.

This function is modified from github.com/gin-contrib/zap.Ginzap

func Info

func Info(msg string, fields ...zap.Field)

Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func NewEncoderConfig

func NewEncoderConfig() zapcore.EncoderConfig

NewEncoderConfig creates and returns a zapcore.EncoderConfig object

func Recovery

func Recovery(logger *zap.Logger, stack bool) gin.HandlerFunc

Recovery returns a gin.HandlerFunc (middleware) that recovers from any panics and logs requests using uber-go/zap. All errors are logged using zap.Error(). stack means whether output the stack info. The stack info is easy to find where the error occurs but the stack info is too large. This function is modified from github.com/gin-contrib/zap.RecoveryWithZap

func Use

func Use(logger *zap.Logger)

Use replaces the default global logger with given one

func Warn

func Warn(msg string, fields ...zap.Field)

Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

Types

type Config

type Config struct {
	Level string
}

Config is the logging configurations

func (Config) Logger

func (cfg Config) Logger() (*zap.Logger, error)

Logger builds and returns a new logger

Jump to

Keyboard shortcuts

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