logger

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	InfoLevel   = zap.InfoLevel
	DebugLevel  = zap.DebugLevel
	WarnLevel   = zap.WarnLevel
	ErrorLevel  = zap.ErrorLevel
	PanicLevel  = zap.PanicLevel
	DPanicLevel = zap.DPanicLevel
	FatalLevel  = zap.FatalLevel
)

Functions

func DummyTimeEncoder

func DummyTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)

func GetDPanicLoggerCounter

func GetDPanicLoggerCounter() uint64

GetDPanicLoggerCounter returns the counter of dpanic level logger.

func GetDebugLoggerCounter

func GetDebugLoggerCounter() uint64

GetDebugLoggerCounter returns the counter of debug level logger.

func GetErrorLoggerCounter

func GetErrorLoggerCounter() uint64

GetErrorLoggerCounter returns the counter of error level logger.

func GetFatalLoggerCounter

func GetFatalLoggerCounter() uint64

GetFatalLoggerCounter returns the counter of fatal level logger.

func GetInfoLoggerCounter

func GetInfoLoggerCounter() uint64

GetInfoLoggerCounter returns the counter of info level logger.

func GetPanicLoggerCounter

func GetPanicLoggerCounter() uint64

GetPanicLoggerCounter returns the counter of panic level logger.

func GetWarnLoggerCounter

func GetWarnLoggerCounter() uint64

GetWarnLoggerCounter returns the counter of warn level logger.

Types

type ArrayEncoder

type ArrayEncoder = zapcore.ArrayEncoder

type ArrayMarshaler

type ArrayMarshaler = zapcore.ArrayMarshaler

type AtomicLevel

type AtomicLevel = zap.AtomicLevel

func NewAtomicLevel

func NewAtomicLevel(level Level) *AtomicLevel

NewAtomicLevel returns a new AtomicLevel.

type Config

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

Config represents the configuration for logger.

func NewCallerConfig

func NewCallerConfig() *Config

NewCallerConfig returns a Config with enable caller.

func NewConfig

func NewConfig() *Config

NewConfig returns a clean Config.

func (*Config) AddOption

func (c *Config) AddOption(option Option) *Config

AddOption adds a new option to config.

func (*Config) AddOptions

func (c *Config) AddOptions(options ...Option) *Config

AddOptions adds options to config.

func (*Config) EnableHostname

func (c *Config) EnableHostname() *Config

EnableHostname enables the hostname for logger.

func (*Config) EnablePID

func (c *Config) EnablePID() *Config

EnablePID enables the pid for logger.

func (*Config) SetLevel

func (c *Config) SetLevel(al *AtomicLevel) *Config

SetLevel sets the logger level.

func (*Config) SetName

func (c *Config) SetName(name string) *Config

SetName sets the logger name.

func (*Config) SetTimeEncoder

func (c *Config) SetTimeEncoder(te TimeEncoder) *Config

SetTimeEncoder sets the time encoder to use.

type Entry

type Entry = zapcore.Entry

type Field

type Field = zapcore.Field

func Any

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

Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.

Since byte/uint8 and rune/int32 are aliases, Any can't differentiate between them. To minimize surprises, []byte values are treated as binary blobs, byte values are treated as uint8, and runes are always treated as integers.

func Array

func Array(key string, val ArrayMarshaler) Field

Array constructs a field with the given key and ArrayMarshaler. It provides a flexible, but still type-safe and efficient, way to add array-like types to the logging context. The struct's MarshalLogArray method is called lazily.

func Binary

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

func Bool

func Bool(key string, val bool) Field

func Boolp

func Boolp(key string, val *bool) Field

func Bools

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

Bools constructs a field that carries a slicex of bools.

func ByteString

func ByteString(key string, val []byte) 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, bss [][]byte) Field

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

func Complex128

func Complex128(key string, val complex128) Field

Complex128 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex128 to interface{}).

func Complex128p

func Complex128p(key string, val *complex128) Field

func Complex128s

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

Complex128s constructs a field that carries a slicex of complex numbers.

func Complex64

func Complex64(key string, val complex64) Field

Complex64 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex64 to interface{}).

func Complex64p

func Complex64p(key string, val *complex64) Field

func Complex64s

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

Complex64s constructs a field that carries a slicex of complex numbers.

func Conn

func Conn(key string, conn net.Conn) Field

func Duration

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

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

func Durationp

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

func Durations

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

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

func Error

func Error(err error) Field

func ErrorString

func ErrorString(err error) Field

func Errors

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

Errors constructs a field that carries a slicex of errors.

func Float32

func Float32(key string, val float32) Field

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

func Float32p

func Float32p(key string, val *float32) Field

func Float32s

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

Float32s constructs a field that carries a slicex of floats.

func Float64

func Float64(key string, val float64) Field

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

func Float64p

func Float64p(key string, val *float64) Field

func Float64s

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

Float64s constructs a field that carries a slicex of floats.

func Int

func Int(key string, val int) Field

Int constructs a field with the given key and value.

func Int16

func Int16(key string, val int16) Field

Int16 constructs a field with the given key and value.

func Int16p

func Int16p(key string, val *int16) Field

func Int16s

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

Int16s constructs a field that carries a slicex of integers.

func Int32

func Int32(key string, val int32) Field

Int32 constructs a field with the given key and value.

func Int32p

func Int32p(key string, val *int32) Field

func Int32s

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

Int32s constructs a field that carries a slicex of integers.

func Int64

func Int64(key string, val int64) Field

Int64 constructs a field with the given key and value.

func Int64p

func Int64p(key string, val *int64) Field

func Int64s

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

Int64s constructs a field that carries a slicex of integers.

func Int8

func Int8(key string, val int8) Field

Int8 constructs a field with the given key and value.

func Int8p

func Int8p(key string, val *int8) Field

func Int8s

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

Int8s constructs a field that carries a slicex of integers.

func Intp

func Intp(key string, val *int) Field

func Ints

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

Ints constructs a field that carries a slicex of integers.

func NamedError

func NamedError(key string, err error) Field

func Namespace

func Namespace(key string) Field

Namespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.

This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.

func NilField

func NilField(key string) Field

func Object

func Object(key string, val zapcore.ObjectMarshaler) 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 Reflect

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

Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.

If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.

func Skip

func Skip() Field

func Stack

func Stack(key string) 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) Field

String constructs a field with the given key and value.

func Stringer

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

Stringer constructs a field with the given key and the output of the value's String method. The Stringer's String method is called lazily.

func Stringp

func Stringp(key string, val *string) Field

func Strings

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

Strings constructs a field that carries a slicex of strings.

func Time

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

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

func Timep

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

func Times

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

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

func Uint

func Uint(key string, val uint) Field

Uint constructs a field with the given key and value.

func Uint16

func Uint16(key string, val uint16) Field

Uint16 constructs a field with the given key and value.

func Uint16p

func Uint16p(key string, val *uint16) Field

func Uint16s

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

Uint16s constructs a field that carries a slicex of unsigned integers.

func Uint32

func Uint32(key string, val uint32) Field

Uint32 constructs a field with the given key and value.

func Uint32p

func Uint32p(key string, val *uint32) Field

func Uint32s

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

Uint32s constructs a field that carries a slicex of unsigned integers.

func Uint64

func Uint64(key string, val uint64) Field

Uint64 constructs a field with the given key and value.

func Uint64p

func Uint64p(key string, val *uint64) Field

func Uint64s

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

Uint64s constructs a field that carries a slicex of unsigned integers.

func Uint8

func Uint8(key string, val uint8) Field

Uint8 constructs a field with the given key and value.

func Uint8p

func Uint8p(key string, val *uint8) Field

func Uint8s

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

Uint8s constructs a field that carries a slicex of unsigned integers.

func Uintp

func Uintp(key string, val *uint) Field

func Uintptr

func Uintptr(key string, val uintptr) Field

Uintptr constructs a field with the given key and value.

func Uintptrp

func Uintptrp(key string, val *uintptr) Field

func Uintptrs

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

Uintptrs constructs a field that carries a slicex of pointer addresses.

func Uints

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

Uints constructs a field that carries a slicex of unsigned integers.

func X509

func X509(key string, x *x509.Certificate) Field

type GeminiLogger

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

func NewGeminiLogger

func NewGeminiLogger(infol, errl Logger) *GeminiLogger

func (*GeminiLogger) Debugf

func (gl *GeminiLogger) Debugf(format string, a ...interface{})

func (*GeminiLogger) Errorf

func (gl *GeminiLogger) Errorf(format string, a ...interface{})

func (*GeminiLogger) Infof

func (gl *GeminiLogger) Infof(format string, a ...interface{})

type Level

type Level = zapcore.Level

func ParseLevel

func ParseLevel(level string) Level

ParseLevel parses the string to level.

type Logger

type Logger interface {
	// Info outputs a message at info level.
	Infof(format string, a ...interface{})

	// Debugf outputs a message at debug level with formatting support.
	Debugf(format string, a ...interface{})

	// Errorf outputs a message at error level with formatting support.
	Errorf(format string, a ...interface{})
}
Example
w := bytes.NewBuffer(nil)
logger, err := New(w, NewCallerConfig().
	SetLevel(NewAtomicLevel(DebugLevel)).
	SetTimeEncoder(DummyTimeEncoder))
if err != nil {
	log.Fatal(err)
}

logger.Info("hello")
logger.Debug("world")

fmt.Println(w.String())
Output:

info	logger/logger_example_test.go:31	hello
debug	logger/logger_example_test.go:32	world

type MapStringString

type MapStringString map[string]string

func (MapStringString) MarshalLogObject

func (mss MapStringString) MarshalLogObject(obj zapcore.ObjectEncoder) error

type ObjectEncoder

type ObjectEncoder = zapcore.ObjectEncoder

type Option

type Option = zap.Option

Option represents an option.

func AddCaller

func AddCaller() Option

AddCaller return a enable caller option.

func AddCallerSkip

func AddCallerSkip(skip int) Option

AddCallerSkip return a caller skip option.

func Hooks

func Hooks(hooks ...func(Entry) error) Option

type PrimitiveArrayEncoder

type PrimitiveArrayEncoder = zapcore.PrimitiveArrayEncoder

type Registry

type Registry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func GetRegistry

func GetRegistry() *Registry

func NewRegistry

func NewRegistry() *Registry

func (*Registry) AllocateLogger

func (r *Registry) AllocateLogger(name string, dsn string,
	opts ...Option) (*SofaLogger, error)

func (*Registry) DoGet

func (r *Registry) DoGet(w http.ResponseWriter, req *http.Request)

func (*Registry) DoPOST

func (r *Registry) DoPOST(w http.ResponseWriter, req *http.Request)

func (*Registry) GetLogger

func (r *Registry) GetLogger(name string) (*SofaLogger, bool)

func (*Registry) MarshalJSON

func (r *Registry) MarshalJSON() ([]byte, error)

func (*Registry) ServeHTTP

func (r *Registry) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Registry) Sync

func (r *Registry) Sync() error

type SofaLogger

type SofaLogger struct {
	// contains filtered or unexported fields
}
var (
	// StdoutLogger represents a logger writes to stdout.
	StdoutLogger *SofaLogger

	// StderrLogger represents a logger writes to stderr.
	StderrLogger *SofaLogger
)

func New

func New(w io.Writer, cf *Config) (*SofaLogger, error)

func (*SofaLogger) DPanic

func (l *SofaLogger) DPanic(msg string, fields ...Field)

func (*SofaLogger) DPanicf

func (l *SofaLogger) DPanicf(format string, v ...interface{})

func (*SofaLogger) Debug

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

func (*SofaLogger) Debugf

func (l *SofaLogger) Debugf(format string, a ...interface{})

func (*SofaLogger) Error

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

func (*SofaLogger) Errorf

func (l *SofaLogger) Errorf(format string, v ...interface{})

func (*SofaLogger) Fatal

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

func (*SofaLogger) Fatalf

func (l *SofaLogger) Fatalf(format string, v ...interface{})

func (*SofaLogger) Info

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

func (*SofaLogger) Infof

func (l *SofaLogger) Infof(format string, a ...interface{})

func (*SofaLogger) IsDebugLevel

func (l *SofaLogger) IsDebugLevel() bool

func (*SofaLogger) Log

func (l *SofaLogger) Log(kv ...interface{}) error

Log implements the https://github.com/go-kit/kit/blob/master/log/log.go

func (*SofaLogger) Named

func (l *SofaLogger) Named(n string) *SofaLogger

func (*SofaLogger) Panic

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

func (*SofaLogger) Panicf

func (l *SofaLogger) Panicf(format string, v ...interface{})

func (*SofaLogger) SetLevel

func (l *SofaLogger) SetLevel(level Level)

func (*SofaLogger) Sync

func (l *SofaLogger) Sync() error

func (*SofaLogger) Warn

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

func (*SofaLogger) Warnf

func (l *SofaLogger) Warnf(format string, a ...interface{})

func (*SofaLogger) With

func (l *SofaLogger) With(fields ...Field) *SofaLogger

func (*SofaLogger) WithOptions

func (l *SofaLogger) WithOptions(options ...Option) *SofaLogger

func (*SofaLogger) XPrint

func (l *SofaLogger) XPrint(err error, msg string, fields ...Field)

func (*SofaLogger) XPrintf

func (l *SofaLogger) XPrintf(err error, format string, a ...interface{})

type SofaLoggerStatus

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

func (*SofaLoggerStatus) GetLevel

func (s *SofaLoggerStatus) GetLevel() *AtomicLevel

func (*SofaLoggerStatus) GetLogger

func (s *SofaLoggerStatus) GetLogger() *SofaLogger

func (*SofaLoggerStatus) GetName

func (s *SofaLoggerStatus) GetName() string

func (*SofaLoggerStatus) GetWriter

func (s *SofaLoggerStatus) GetWriter() *sofawriter.Writer

func (*SofaLoggerStatus) MarshalJSON

func (s *SofaLoggerStatus) MarshalJSON() ([]byte, error)

type TimeEncoder

type TimeEncoder = zapcore.TimeEncoder

Jump to

Keyboard shortcuts

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