log

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// NameZapJSONLogger ZapJSONLogger
	NameZapJSONLogger = "zapJSONLogger"
	// NameConsoleLogger ZapConsoleLogger
	NameConsoleLogger = "zapConsoleLogger"

	// NameKey Name
	NameKey = "name"
	// StacktraceKey Stack
	StacktraceKey = "stack"
	// MessageKey Message
	MessageKey = "message"
	// LevelKey level
	LevelKey = "level"
	// TimeKey  Time
	TimeKey = "time"
	// CallerKey  Caller
	CallerKey = "caller"

	// DefaultTimePattern time pattern
	DefaultTimePattern = "2006-01-02 15:04:05"
)

const string

Variables

This section is empty.

Functions

func AccessLogFunc

func AccessLogFunc(log *Logger) gin.HandlerFunc

AccessLogFunc 记录HTTP请求日志

func Bool

func Bool(key string, val bool) zap.Field

Bool constructs a field that carries a bool.

func Bools

func Bools(key string, vars []bool) zap.Field

Bools constructs a field that carries a slice of bools.

func ByteString

func ByteString(key string, val []byte) zap.Field

ByteString constructs a field that carries UTF-8 encoded text as a []byte. To log opaque binary blobs (which aren't necessarily valid UTF-8), use Binary.

func ByteStrings

func ByteStrings(key string, vals [][]byte) zap.Field

ByteStrings constructs a field that carries a slice of []byte, each of which must be UTF-8 encoded text.

func Debug

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

Debug log

func Duration

func Duration(key string, val time.Duration) zap.Field

Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.

func Durations

func Durations(key string, vals []time.Duration) zap.Field

Durations constructs a field that carries a slice of time.Durations.

func Err

func Err(err error) zap.Field

Err is shorthand for the common idiom NamedError("error", err).

func Error

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

Error log

func Errs

func Errs(key string, errs []error) zap.Field

Errs constructs a field that carries a slice of errors.

func Fatal

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

Fatal log

func Float32

func Float32(key string, val float32) zap.Field

Float32 constructs a field that carries a float32. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float32s

func Float32s(key string, vals []float32) zap.Field

Float32s constructs a field that carries a slice of floats.

func Float64

func Float64(key string, val float64) zap.Field

Float64 constructs a field that carries a float64. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float64s

func Float64s(key string, vals []float64) zap.Field

Float64s constructs a field that carries a slice of floats.

func Info

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

Info log

func Int

func Int(key string, val int) zap.Field

Int constructs a field with the given key and value.

func Int16

func Int16(key string, val int16) zap.Field

Int16 constructs a field with the given key and value.

func Int16s

func Int16s(key string, vals []int16) zap.Field

Int16s constructs a field that carries a slice of integers.

func Int32

func Int32(key string, val int32) zap.Field

Int32 constructs a field with the given key and value.

func Int32s

func Int32s(key string, vals []int32) zap.Field

Int32s constructs a field that carries a slice of integers.

func Int64

func Int64(key string, val int64) zap.Field

Int64 constructs a field with the given key and value.

func Int64s

func Int64s(key string, vals []int64) zap.Field

Int64s constructs a field that carries a slice of integers.

func Int8

func Int8(key string, val int8) zap.Field

Int8 constructs a Field with the given key and value.

func Int8s

func Int8s(key string, vals []int8) zap.Field

Int8s constructs a Field with the given key and value.

func Ints

func Ints(key string, vals []int) zap.Field

Ints constructs a field that carries a slice of integers.

func Object

func Object(key string, val interface{}) zap.Field

Object constructs a field with the given key and ObjectMarshaler. It provides a flexible, but still type-safe and efficient, way to add map- or struct-like user-defined types to the logging context. The struct's MarshalLogObject method is called lazily.

func Panic

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

Panic log

func SetLogger

func SetLogger(log *Logger)

SetLogger set goLog

func Stack

func Stack(key string) zap.Field

Stack constructs a field that stores a stacktrace of the current goroutine under provided key. Keep in mind that taking a stacktrace is eager and expensive (relatively speaking); this function both makes an allocation and takes about two microseconds.

func String

func String(key string, val string) zap.Field

String constructs a field with the given key and value.

func Strings

func Strings(key string, val []string) zap.Field

Strings constructs a field that carries a slice of strings.

func Time

func Time(key string, val time.Time) zap.Field

Time constructs a Field with the given key and value. The encoder controls how the time is serialized.

func Times

func Times(key string, vals []time.Time) zap.Field

Times constructs a field that carries a slice of time.Times.

func Uint

func Uint(key string, val uint) zap.Field

Uint constructs a Field with the given key and value.

func Uint16

func Uint16(key string, val uint16) zap.Field

Uint16 constructs a field with the given key and value.

func Uint16s

func Uint16s(key string, vals []uint16) zap.Field

Uint16s constructs a field that carries a slice of integers.

func Uint32

func Uint32(key string, val uint32) zap.Field

Uint32 constructs a field with the given key and value.

func Uint32s

func Uint32s(key string, vals []uint32) zap.Field

Uint32s constructs a field that carries a slice of integers.

func Uint64

func Uint64(key string, val uint64) zap.Field

Uint64 constructs a field with the given key and value.

func Uint64s

func Uint64s(key string, vals []uint64) zap.Field

Uint64s constructs a field that carries a slice of integers.

func Uint8

func Uint8(key string, val uint8) zap.Field

Uint8 constructs a field with the given key and value.

func Uint8s

func Uint8s(key string, vals []uint8) zap.Field

Uint8s constructs a field that carries a slice of integers.

func Uints

func Uints(key string, vals []uint) zap.Field

Uints constructs a Field with the given key and value.

func Warn

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

Warn log

Types

type Config

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

Config for zap logger

type EncoderType

type EncoderType int

EncoderType define

const (
	// JSONEncoder Defined JSON encoder type for logger
	JSONEncoder EncoderType = iota
	// ConsoleEncoder Defined Console encoder type for logger
	ConsoleEncoder
)

type Level added in v1.0.1

type Level int

LogLevel define

const (
	// DebugLevel debug
	DebugLevel Level = iota
	// InfoLevel info
	InfoLevel
	// WarnLevel warn
	WarnLevel
	// ErrorLevel error
	ErrorLevel
	// PanicLevel panic
	PanicLevel
	// FatalLevel fatal
	FatalLevel
)

type Logger

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

Logger use zap logger

func GetLogger

func GetLogger() *Logger

GetLogger get goLog

func NewLogger

func NewLogger(opts ...Option) (*Logger, error)

NewLogger new logger with the given Options default use InfoLevel, JSONEncoder, os.Stdout

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zap.Field)

Debug log

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...zap.Field)

Error log

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...zap.Field)

Fatal log

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zap.Field)

Info log

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...zap.Field)

Panic log

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...zap.Field)

Warn log

type Option

type Option func(c *Config)

Option set the option to Config

func WithCaller

func WithCaller() Option

WithCaller set config withCaller

func WithConsoleEncoder

func WithConsoleEncoder() Option

WithConsoleEncoder set config encoder with ConsoleEncoder

func WithDebugLevel

func WithDebugLevel() Option

WithDebugLevel set config debug level

func WithErrorLevel

func WithErrorLevel() Option

WithErrorLevel set config error level

func WithFatalLevel

func WithFatalLevel() Option

WithFatalLevel set config fatal level

func WithInfoLevel

func WithInfoLevel() Option

WithInfoLevel set config info level

func WithJSONEncoder

func WithJSONEncoder() Option

WithJSONEncoder set config encoder with JSONEncoder

func WithNoLock

func WithNoLock() Option

WithNoLock set config withNoLock

func WithOutput

func WithOutput(o io.Writer) Option

WithOutput set config Output

func WithPanicLevel

func WithPanicLevel() Option

WithPanicLevel set config panic level

func WithTimePattern

func WithTimePattern(pattern string) Option

WithTimePattern set config timePattern

func WithWarnLevel

func WithWarnLevel() Option

WithWarnLevel set config warn level

type RotateWriter

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

RotateWriter writer

func NewRotateWriter

func NewRotateWriter(fileName, pattern string) (*RotateWriter, error)

NewRotateWriter return new RotateWriter @fileName target file name @pattern time pattern

func (*RotateWriter) Write

func (w *RotateWriter) Write(output []byte) (int, error)

Write satisfies the io.Writer interface.

Jump to

Keyboard shortcuts

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