Documentation
¶
Index ¶
- Variables
- func DummyTimeEncoder(t time.Time, enc PrimitiveArrayEncoder)
- func GetDPanicLoggerCounter() uint64
- func GetDebugLoggerCounter() uint64
- func GetErrorLoggerCounter() uint64
- func GetFatalLoggerCounter() uint64
- func GetInfoLoggerCounter() uint64
- func GetPanicLoggerCounter() uint64
- func GetWarnLoggerCounter() uint64
- type ArrayEncoder
- type ArrayMarshaler
- type AtomicLevel
- type Config
- func (c *Config) AddOption(option Option) *Config
- func (c *Config) AddOptions(options ...Option) *Config
- func (c *Config) EnableHostname() *Config
- func (c *Config) EnablePID() *Config
- func (c *Config) SetLevel(al *AtomicLevel) *Config
- func (c *Config) SetName(name string) *Config
- func (c *Config) SetTimeEncoder(te TimeEncoder) *Config
- type Entry
- type Field
- func Any(key string, value interface{}) Field
- func Array(key string, val ArrayMarshaler) Field
- func Binary(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func Boolp(key string, val *bool) Field
- func Bools(key string, bs []bool) Field
- func ByteString(key string, val []byte) Field
- func ByteStrings(key string, bss [][]byte) Field
- func Complex128(key string, val complex128) Field
- func Complex128p(key string, val *complex128) Field
- func Complex128s(key string, nums []complex128) Field
- func Complex64(key string, val complex64) Field
- func Complex64p(key string, val *complex64) Field
- func Complex64s(key string, nums []complex64) Field
- func Conn(key string, conn net.Conn) Field
- func Duration(key string, val time.Duration) Field
- func Durationp(key string, val *time.Duration) Field
- func Durations(key string, ds []time.Duration) Field
- func Error(err error) Field
- func ErrorString(err error) Field
- func Errors(key string, errs []error) Field
- func Float32(key string, val float32) Field
- func Float32p(key string, val *float32) Field
- func Float32s(key string, nums []float32) Field
- func Float64(key string, val float64) Field
- func Float64p(key string, val *float64) Field
- func Float64s(key string, nums []float64) Field
- func Int(key string, val int) Field
- func Int16(key string, val int16) Field
- func Int16p(key string, val *int16) Field
- func Int16s(key string, nums []int16) Field
- func Int32(key string, val int32) Field
- func Int32p(key string, val *int32) Field
- func Int32s(key string, nums []int32) Field
- func Int64(key string, val int64) Field
- func Int64p(key string, val *int64) Field
- func Int64s(key string, nums []int64) Field
- func Int8(key string, val int8) Field
- func Int8p(key string, val *int8) Field
- func Int8s(key string, nums []int8) Field
- func Intp(key string, val *int) Field
- func Ints(key string, nums []int) Field
- func NamedError(key string, err error) Field
- func Namespace(key string) Field
- func NilField(key string) Field
- func Object(key string, val zapcore.ObjectMarshaler) Field
- func Reflect(key string, val interface{}) Field
- func Skip() Field
- func Stack(key string) Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Stringp(key string, val *string) Field
- func Strings(key string, ss []string) Field
- func Time(key string, val time.Time) Field
- func Timep(key string, val *time.Time) Field
- func Times(key string, ts []time.Time) Field
- func Uint(key string, val uint) Field
- func Uint16(key string, val uint16) Field
- func Uint16p(key string, val *uint16) Field
- func Uint16s(key string, nums []uint16) Field
- func Uint32(key string, val uint32) Field
- func Uint32p(key string, val *uint32) Field
- func Uint32s(key string, nums []uint32) Field
- func Uint64(key string, val uint64) Field
- func Uint64p(key string, val *uint64) Field
- func Uint64s(key string, nums []uint64) Field
- func Uint8(key string, val uint8) Field
- func Uint8p(key string, val *uint8) Field
- func Uint8s(key string, nums []uint8) Field
- func Uintp(key string, val *uint) Field
- func Uintptr(key string, val uintptr) Field
- func Uintptrp(key string, val *uintptr) Field
- func Uintptrs(key string, us []uintptr) Field
- func Uints(key string, nums []uint) Field
- func X509(key string, x *x509.Certificate) Field
- type GeminiLogger
- type Level
- type Logger
- type MapStringString
- type ObjectEncoder
- type Option
- type PrimitiveArrayEncoder
- type Registry
- func (r *Registry) AllocateLogger(name string, dsn string, opts ...Option) (*SofaLogger, error)
- func (r *Registry) DoGet(w http.ResponseWriter, req *http.Request)
- func (r *Registry) DoPOST(w http.ResponseWriter, req *http.Request)
- func (r *Registry) GetLogger(name string) (*SofaLogger, bool)
- func (r *Registry) MarshalJSON() ([]byte, error)
- func (r *Registry) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Registry) Sync() error
- type SofaLogger
- func (l *SofaLogger) DPanic(msg string, fields ...Field)
- func (l *SofaLogger) DPanicf(format string, v ...interface{})
- func (l *SofaLogger) Debug(msg string, fields ...Field)
- func (l *SofaLogger) Debugf(format string, a ...interface{})
- func (l *SofaLogger) Error(msg string, fields ...Field)
- func (l *SofaLogger) Errorf(format string, v ...interface{})
- func (l *SofaLogger) Fatal(msg string, fields ...Field)
- func (l *SofaLogger) Fatalf(format string, v ...interface{})
- func (l *SofaLogger) Info(msg string, fields ...Field)
- func (l *SofaLogger) Infof(format string, a ...interface{})
- func (l *SofaLogger) IsDebugLevel() bool
- func (l *SofaLogger) Log(kv ...interface{}) error
- func (l *SofaLogger) Named(n string) *SofaLogger
- func (l *SofaLogger) Panic(msg string, fields ...Field)
- func (l *SofaLogger) Panicf(format string, v ...interface{})
- func (l *SofaLogger) SetLevel(level Level)
- func (l *SofaLogger) Sync() error
- func (l *SofaLogger) Warn(msg string, fields ...Field)
- func (l *SofaLogger) Warnf(format string, a ...interface{})
- func (l *SofaLogger) With(fields ...Field) *SofaLogger
- func (l *SofaLogger) WithOptions(options ...Option) *SofaLogger
- func (l *SofaLogger) XPrint(err error, msg string, fields ...Field)
- func (l *SofaLogger) XPrintf(err error, format string, a ...interface{})
- type SofaLoggerStatus
- type TimeEncoder
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 (*Config) AddOptions ¶
AddOptions adds options to config.
func (*Config) EnableHostname ¶
EnableHostname enables the hostname for logger.
func (*Config) SetLevel ¶
func (c *Config) SetLevel(al *AtomicLevel) *Config
SetLevel sets the logger level.
func (*Config) SetTimeEncoder ¶
func (c *Config) SetTimeEncoder(te TimeEncoder) *Config
SetTimeEncoder sets the time encoder to use.
type Field ¶
func Any ¶
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 ByteString ¶
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 ¶
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 ¶
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 Complex64s ¶
Complex64s constructs a field that carries a slicex of complex numbers.
func Duration ¶
Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.
func ErrorString ¶
func Float32 ¶
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 Float64 ¶
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 NamedError ¶
func Namespace ¶
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 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 ¶
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 Stack ¶
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 Stringer ¶
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 Time ¶
Time constructs a Field with the given key and value. The encoder controls how the time is serialized.
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 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 ¶
func (MapStringString) MarshalLogObject ¶
func (mss MapStringString) MarshalLogObject(obj zapcore.ObjectEncoder) error
type ObjectEncoder ¶
type ObjectEncoder = zapcore.ObjectEncoder
type PrimitiveArrayEncoder ¶
type PrimitiveArrayEncoder = zapcore.PrimitiveArrayEncoder
type Registry ¶
func GetRegistry ¶
func GetRegistry() *Registry
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) AllocateLogger ¶
func (*Registry) MarshalJSON ¶
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 (*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) 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