logger

package
v0.0.0-...-15a51b0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOGGER_FILE_STDOUT = "stdout"
	LOGGER_FILE_STDERR = "stderr"

	LOGGER_ENCODER_JSON    = "json"
	LOGGER_ENCODER_CONSOLE = "console"
)

Variables

View Source
var (

	// ErrLoggerExists logger is already exists.
	ErrLoggerExists = errors.New("logger already exists")
	// ErrLoggerExists logger is not exists.
	ErrLoggerNotExists = errors.New("logger does not exists")
)

Functions

func Any

func Any(key string, value interface{}) zap.Field

func Array

func Array(key string, val zapcore.ArrayMarshaler) zap.Field

func Binary

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

func Bool

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

func Boolp

func Boolp(key string, val *bool) zap.Field

func Bools

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

func ByteString

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

func ByteStrings

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

func Complex128

func Complex128(key string, val complex128) zap.Field

func Complex128p

func Complex128p(key string, val *complex128) zap.Field

func Complex128s

func Complex128s(key string, nums []complex128) zap.Field

func Complex64

func Complex64(key string, val complex64) zap.Field

func Complex64p

func Complex64p(key string, val *complex64) zap.Field

func Complex64s

func Complex64s(key string, nums []complex64) zap.Field

func Duration

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

func Durationp

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

func Durations

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

func Error

func Error(err error) zap.Field

func Errors

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

func Float32

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

func Float32p

func Float32p(key string, val *float32) zap.Field

func Float32s

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

func Float64

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

func Float64p

func Float64p(key string, val *float64) zap.Field

func Float64s

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

func Inline

func Inline(val zapcore.ObjectMarshaler) zap.Field

func Int

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

func Int16

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

func Int16p

func Int16p(key string, val *int16) zap.Field

func Int16s

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

func Int32

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

func Int32p

func Int32p(key string, val *int32) zap.Field

func Int32s

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

func Int64

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

func Int64p

func Int64p(key string, val *int64) zap.Field

func Int64s

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

func Int8

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

func Int8p

func Int8p(key string, val *int8) zap.Field

func Int8s

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

func Intp

func Intp(key string, val *int) zap.Field

func Ints

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

func L

func L() *zap.Logger

L global logger with field

func NamedError

func NamedError(key string, err error) zap.Field

func Namespace

func Namespace(key string) zap.Field

func NewLogger

func NewLogger(cfg Config) *zap.Logger

NewLogger Create a logger, reutrn zap logger.

func Object

func Object(key string, val zapcore.ObjectMarshaler) zap.Field

func Reflect

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

func S

func S() *zap.SugaredLogger

S() global logger without field

func SetGlobal

func SetGlobal(config Config)

SetGlobal configure a global logger to use, after configured, use zap.L() or zap.S(), do not need to import package logger again.

func Skip

func Skip() zap.Field

func Stack

func Stack(key string) zap.Field

func StackSkip

func StackSkip(key string, skip int) zap.Field

func String

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

func Stringer

func Stringer(key string, val fmt.Stringer) zap.Field

func Stringp

func Stringp(key string, val *string) zap.Field

func Strings

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

func Time

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

func Timep

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

func Times

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

func Uint

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

func Uint16

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

func Uint16p

func Uint16p(key string, val *uint16) zap.Field

func Uint16s

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

func Uint32

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

func Uint32p

func Uint32p(key string, val *uint32) zap.Field

func Uint32s

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

func Uint64

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

func Uint64p

func Uint64p(key string, val *uint64) zap.Field

func Uint64s

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

func Uint8

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

func Uint8p

func Uint8p(key string, val *uint8) zap.Field

func Uint8s

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

func Uintp

func Uintp(key string, val *uint) zap.Field

func Uintptr

func Uintptr(key string, val uintptr) zap.Field

func Uintptrp

func Uintptrp(key string, val *uintptr) zap.Field

func Uintptrs

func Uintptrs(key string, us []uintptr) zap.Field

func Uints

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

Types

type Config

type Config struct {
	// Filenames filename to storage log, could be stdout, stderr and files.
	Filenames []string `json:"filename" yaml:"filename"`
	// MaxSize log file size, if filename is a path to file, default to 100 (mb).
	MaxSize int `json:"max_size" yaml:"max_size"`
	// MaxAge log file retain time, if filename is a path to file, default to 0, not retain (day).
	MaxAge int `json:"max_age" yaml:"max_age"`
	// MaxBackups max files to storage, if filename is a path to file, , default to 0, not retain.
	MaxBackups int `json:"max_backups" yaml:"max_backups"`
	// LocalTime using local time, if filename is a path to file.
	LocalTime bool `json:"local_time" yaml:"local_time"`
	// Compress rotated file is compressed, if filename is a path to file.
	Compress bool `json:"compress" yaml:"compress"`
	// LogLevel support debug, info, warn, error, dpanic, panic, fatal, do not care uppgercase or lowwercase.
	LogLevel string `json:"log_level" yaml:"log_level"`
	// Encoder encoder log format to store or print, support json and console.
	Encoder string `json:"encoder" yaml:"encoder"`
}

Config Logger config.

func (*Config) Build

func (c *Config) Build()

Build build config to fix all empty values.

type LoggerPool

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

LoggerPool is a pool to manager logger for different business.

func NewPool

func NewPool() *LoggerPool

func P

func P() *LoggerPool

P global pool.

func (*LoggerPool) Add

func (p *LoggerPool) Add(name string, config Config) (*zap.Logger, error)

Add add a named logger to pool.

func (*LoggerPool) Get

func (p *LoggerPool) Get(name string) (*zap.Logger, error)

Get get a named logger from pool.

func (*LoggerPool) Remove

func (p *LoggerPool) Remove(name string) error

Remove remove a named logger from pool.

Jump to

Keyboard shortcuts

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