logger

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

logger

Logger wrapper for Smarp Backend

Documentation

Index

Constants

View Source
const EnvPrefix = "LOG"

EnvPrefix environment prefix for log config

Variables

This section is empty.

Functions

func ApplyConfig

func ApplyConfig() (err error)

ApplyConfig apply new config to global logger

func Debug

func Debug(message string, args ...interface{})

Debug prints a debug message

func Debugw

func Debugw(message string, keyValues ...interface{})

Debugw prints a debug message

func Error

func Error(message string, args ...interface{})

Error logs a message with some additional context

func Errorw

func Errorw(message string, keyValues ...interface{})

Errorw logs a message with some additional context

func Fatal

func Fatal(message string, args ...interface{})

Fatal logs a message to stderr and then calls an os.Exit

func Fatalw

func Fatalw(message string, keyValues ...interface{})

Fatalw logs a message to stderr and then calls an os.Exit

func GetLoggerConfig

func GetLoggerConfig() zap.Config

GetLoggerConfig return default zap config

func GoogleLevelEncoder added in v1.0.2

func GoogleLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

func Info

func Info(message string, args ...interface{})

Info logs a message with some additional context

func Infow

func Infow(message string, keyValues ...interface{})

Infow logs a message with some additional context

func Panic

func Panic(message string, args ...interface{})

Panic logs a message with some additional context, then panics

func Panicw

func Panicw(message string, keyValues ...interface{})

Panicw logs a message with some additional context, then panics

func Print

func Print(v ...interface{})

Print logs a message at Info level

func Printf

func Printf(format string, v ...interface{})

Printf logs a message at Info level

func Println

func Println(v ...interface{})

Println logs a message at Info level

func SetErrorOutput

func SetErrorOutput(errorOutput string)

SetErrorOutput set error output

func SetFormatter

func SetFormatter(encoding string, encoderConfig zapcore.EncoderConfig)

SetFormatter set formatter

func SetLevel

func SetLevel(level zapcore.Level)

SetLevel set login level

func SetOutput

func SetOutput(output string)

SetOutput set output

func Warn

func Warn(message string, args ...interface{})

Warn logs a message with some additional context

func Warning

func Warning(message string, args ...interface{})

Warning logs a message with some additional context

func Warnw

func Warnw(message string, keyValues ...interface{})

Warnw logs a message with some additional context

func With

func With(args ...interface{})

With return logger with fields

Types

type Chain

type Chain interface {
	Copy() Chain
	Debug(msg string, args ...interface{})
	Info(msg string, args ...interface{})
	Warn(msg string, args ...interface{})
	Warning(msg string, args ...interface{})
	Error(msg string, args ...interface{})
	Fatal(msg string, args ...interface{})
	Panic(msg string, args ...interface{})

	WithBinary(key string, val []byte) Chain
	WithBool(key string, val bool) Chain
	WithByteString(key string, val []byte) Chain
	WithComplex128(key string, val complex128) Chain
	WithComplex64(key string, val complex64) Chain
	WithFloat64(key string, val float64) Chain
	WithFloat32(key string, val float32) Chain
	WithInt(key string, val int) Chain
	WithInt64(key string, val int64) Chain
	WithInt32(key string, val int32) Chain
	WithInt16(key string, val int16) Chain
	WithInt8(key string, val int8) Chain
	WithString(key string, val string) Chain
	WithError(val error) Chain
	WithNamedError(key string, err error) Chain
	WithUint(key string, val uint) Chain
	WithUint64(key string, val uint64) Chain
	WithUint32(key string, val uint32) Chain
	WithUint16(key string, val uint16) Chain
	WithUint8(key string, val uint8) Chain
	WithUintptr(key string, val uintptr) Chain
	WithReflect(key string, val interface{}) Chain
	WithNamespace(key string) Chain
	WithStringer(key string, val fmt.Stringer) Chain
	WithTime(key string, val time.Time) Chain
	WithStack(key string) Chain
	WithDuration(key string, val time.Duration) Chain
	WithAny(key string, val interface{}) Chain
	WithField(key string, value interface{}) Chain
	WithFields(fields Fields) Chain

	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})

	Log(keyvals ...interface{}) error
	Output(calldepth int, s string) error
}

Chain context provide functionality for log with predefined values

func ChainWith

func ChainWith(c Chain, keyvals ...interface{}) Chain

func GetChain

func GetChain() Chain

GetChain return chain

func WithError

func WithError(err error) Chain

WithError return logger with given error

func WithField

func WithField(key string, value interface{}) Chain

WithField return logger with given field

func WithFields

func WithFields(fields Fields) Chain

WithFields return logger with given fields

type Entry

type Entry struct {
	Logger *zap.Logger
	// contains filtered or unexported fields
}

Entry contains values of given chain

func (*Entry) Copy

func (c *Entry) Copy() Chain

Copy copy Chain

func (*Entry) Debug

func (c *Entry) Debug(msg string, args ...interface{})

Debug logs a message at DebugLevel

func (*Entry) Error

func (c *Entry) Error(msg string, args ...interface{})

Error logs a message at ErrorLevel

func (*Entry) Fatal

func (c *Entry) Fatal(msg string, args ...interface{})

Fatal logs a message at FatalLevel

func (*Entry) Info

func (c *Entry) Info(msg string, args ...interface{})

Info logs a message at InfoLevel

func (*Entry) Log

func (c *Entry) Log(keyvals ...interface{}) error

Log logs as Info

func (*Entry) Output

func (c *Entry) Output(calldepth int, s string) error

Output Add support nsq output

func (*Entry) Panic

func (c *Entry) Panic(msg string, args ...interface{})

Panic logs a message at PanicLevel

func (*Entry) Print

func (c *Entry) Print(v ...interface{})

Print logs a message at PanicLevel

func (*Entry) Printf

func (c *Entry) Printf(format string, v ...interface{})

Printf logs a message at PanicLevel

func (*Entry) Println

func (c *Entry) Println(v ...interface{})

Println logs a message at PanicLevel

func (*Entry) Warn

func (c *Entry) Warn(msg string, args ...interface{})

Warn logs a message at WarnLevel

func (*Entry) Warning

func (c *Entry) Warning(msg string, args ...interface{})

Warning logs a message at WarnLevel

func (*Entry) WithAny

func (c *Entry) WithAny(key string, val interface{}) Chain

WithAny takes a key and an arbitrary value and chooses the best way to represent them as a field

func (*Entry) WithBinary

func (c *Entry) WithBinary(key string, val []byte) Chain

WithBinary add a field that carries an opaque binary blob.

func (*Entry) WithBool

func (c *Entry) WithBool(key string, val bool) Chain

WithBool add a field that carries a bool.

func (*Entry) WithByteString

func (c *Entry) WithByteString(key string, val []byte) Chain

WithByteString add a field that carries UTF-8 encoded text as a []byte.

func (*Entry) WithComplex128

func (c *Entry) WithComplex128(key string, val complex128) Chain

WithComplex128 add a field that carries a complex number.

func (*Entry) WithComplex64

func (c *Entry) WithComplex64(key string, val complex64) Chain

WithComplex64 add a field that carries a complex number

func (*Entry) WithDuration

func (c *Entry) WithDuration(key string, val time.Duration) Chain

WithDuration add a field with the given key and value.

func (*Entry) WithError

func (c *Entry) WithError(val error) Chain

WithError add a field with the given error value.

func (*Entry) WithField

func (c *Entry) WithField(key string, value interface{}) Chain

WithField return logger with given field

func (*Entry) WithFields

func (c *Entry) WithFields(fields Fields) Chain

WithFields return logger with given fields

func (*Entry) WithFloat32

func (c *Entry) WithFloat32(key string, val float32) Chain

WithFloat32 add a field that carries a float32

func (*Entry) WithFloat64

func (c *Entry) WithFloat64(key string, val float64) Chain

WithFloat64 add a field that carries a float64

func (*Entry) WithInt

func (c *Entry) WithInt(key string, val int) Chain

WithInt add a field with the given key and value.

func (*Entry) WithInt16

func (c *Entry) WithInt16(key string, val int16) Chain

WithInt16 add a field with the given key and value.

func (*Entry) WithInt32

func (c *Entry) WithInt32(key string, val int32) Chain

WithInt32 add a field with the given key and value.

func (*Entry) WithInt64

func (c *Entry) WithInt64(key string, val int64) Chain

WithInt64 add a field with the given key and value.

func (*Entry) WithInt8

func (c *Entry) WithInt8(key string, val int8) Chain

WithInt8 add a field with the given key and value.

func (*Entry) WithNamedError

func (c *Entry) WithNamedError(key string, err error) Chain

WithNamedError add a field with the given key and value.

func (*Entry) WithNamespace

func (c *Entry) WithNamespace(key string) Chain

WithNamespace creates a named, isolated scope within the logger's context

func (*Entry) WithReflect

func (c *Entry) WithReflect(key string, val interface{}) Chain

WithReflect constructs a field with the given key and value.

func (*Entry) WithStack

func (c *Entry) WithStack(key string) Chain

WithStack constructs a field that stores a stacktrace

func (*Entry) WithString

func (c *Entry) WithString(key string, val string) Chain

WithString add a field with the given key and value.

func (*Entry) WithStringer

func (c *Entry) WithStringer(key string, val fmt.Stringer) Chain

WithStringer add a field with the given key and value.

func (*Entry) WithTime

func (c *Entry) WithTime(key string, val time.Time) Chain

WithTime add a field with the given key and value.

func (*Entry) WithUint

func (c *Entry) WithUint(key string, val uint) Chain

WithUint add a field with the given key and value.

func (*Entry) WithUint16

func (c *Entry) WithUint16(key string, val uint16) Chain

WithUint16 add a field with the given key and value.

func (*Entry) WithUint32

func (c *Entry) WithUint32(key string, val uint32) Chain

WithUint32 add a field with the given key and value.

func (*Entry) WithUint64

func (c *Entry) WithUint64(key string, val uint64) Chain

WithUint64 add a field with the given key and value.

func (*Entry) WithUint8

func (c *Entry) WithUint8(key string, val uint8) Chain

WithUint8 add a field with the given key and value.

func (*Entry) WithUintptr

func (c *Entry) WithUintptr(key string, val uintptr) Chain

WithUintptr add a field with the given key and value.

type Fields

type Fields map[string]interface{}

Fields type, used to pass to `WithFields`.

type GoogleSeverity added in v1.0.2

type GoogleSeverity int
const (
	GoogleSeverityDefault   GoogleSeverity = 0
	GoogleSeverityDebug     GoogleSeverity = 100
	GoogleSeverityInfo      GoogleSeverity = 200
	GoogleSeverityNotice    GoogleSeverity = 300
	GoogleSeverityWarning   GoogleSeverity = 400
	GoogleSeverityError     GoogleSeverity = 500
	GoogleSeverityCritical  GoogleSeverity = 600
	GoogleSeverityAlert     GoogleSeverity = 700
	GoogleSeverityEmergency GoogleSeverity = 800
)

func LevelToGoogleSeverity added in v1.0.2

func LevelToGoogleSeverity(level zapcore.Level) GoogleSeverity

func (GoogleSeverity) String added in v1.0.2

func (l GoogleSeverity) String() string

type Log

type Log interface {
	Debugw(msg string, keyValues ...interface{})
	Infow(msg string, keyValues ...interface{})
	Warnw(msg string, keyValues ...interface{})
	Errorw(msg string, keyValues ...interface{})
	Panicw(msg string, keyValues ...interface{})
	Fatalw(msg string, keyValues ...interface{})

	Chain() Chain
}

Log describe log wrapper interface

type LogConfig

type LogConfig struct {
	Name              string `default:"" split_words:"true"`
	Level             int8   `default:"0" split_words:"true"`
	DisableCaller     bool   `default:"false" split_words:"true"`
	DisableStacktrace bool   `default:"false" split_words:"true"`
}

LogConfig contains name and level for log

func GetLogConfigFromEnv

func GetLogConfigFromEnv() (*LogConfig, error)

GetLogConfigFromEnv return log configs bases on environment variables

type WrappedLogger

type WrappedLogger struct {
	*zap.SugaredLogger
}

WrappedLogger is a logger that is wrapped with a config file It takes a config to determine which level its running at

func GetDefaultWrappedLogger

func GetDefaultWrappedLogger(cfg *LogConfig, localCfg zap.Config) *WrappedLogger

GetDefaultWrappedLogger return default wrapper

func Logger

func Logger() *WrappedLogger

Logger return logger

func NewWrappedLogger

func NewWrappedLogger(name string, config zap.Config, args ...interface{}) (*WrappedLogger, error)

NewWrappedLogger creates a new logger which wraps the given config

func WrapCore

func WrapCore(core zapcore.Core, options ...zap.Option) (*WrappedLogger, error)

WrapCore wrap zap core

func (*WrappedLogger) Chain

func (w *WrappedLogger) Chain() Chain

Chain return new chain with local context

func (*WrappedLogger) Output

func (w *WrappedLogger) Output(calldepth int, s string) error

Output add support nsq output

func (*WrappedLogger) Print

func (w *WrappedLogger) Print(v ...interface{})

Print logs a message at Info level

func (*WrappedLogger) Printf

func (w *WrappedLogger) Printf(format string, v ...interface{})

Printf logs a message at Info level

func (*WrappedLogger) Println

func (w *WrappedLogger) Println(v ...interface{})

Println logs a message at Info level

func (*WrappedLogger) With

func (w *WrappedLogger) With(v ...interface{}) *WrappedLogger

With return new wrapped logger with default fields

Jump to

Keyboard shortcuts

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