logger

package
v0.0.0-...-137c36e Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package logger Provides structured & deprecated unstructured logging facade to facilitate logging to different providers and multiple loggers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 Binary

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

Binary constructs a field that carries an opaque binary blob.

Binary data is serialized in an encoding-appropriate format. For example, zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text, use ByteString.

func Bool

func Bool(key string, val bool) Field

Bool constructs a field that carries a bool.

func Boolp

func Boolp(key string, val *bool) Field

Boolp constructs a field that carries a *bool. The returned Field will safely and explicitly represent `nil` when appropriate.

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 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

Complex128p constructs a field that carries a *complex128. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Complex64p constructs a field that carries a *complex64. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Durationp constructs a field that carries a *time.Duration. The returned Field will safely and explicitly represent `nil` when appropriate.

func Error

func Error(err error) Field

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

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 marshaling is necessarily lazy.

func Float32p

func Float32p(key string, val *float32) Field

Float32p constructs a field that carries a *float32. The returned Field will safely and explicitly represent `nil` when appropriate.

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 marshaling is necessarily lazy.

func Float64p

func Float64p(key string, val *float64) Field

Float64p constructs a field that carries a *float64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Inline

func Inline(val zapcore.ObjectMarshaler) Field

Inline constructs a Field that is similar to Object, but it will add the elements of the provided ObjectMarshaler to the current namespace.

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

Int16p constructs a field that carries a *int16. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Int32p constructs a field that carries a *int32. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Int64p constructs a field that carries a *int64. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Int8p constructs a field that carries a *int8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Intp

func Intp(key string, val *int) Field

Intp constructs a field that carries a *int. The returned Field will safely and explicitly represent `nil` when appropriate.

func NamedError

func NamedError(key string, err error) Field

NamedError constructs a field that lazily stores err.Error() under the provided key. Errors which also implement fmt.Formatter (like those produced by github.com/pkg/errors) will also have their verbose representation stored under key+"Verbose". If passed a nil error, the field is a no-op.

For the common case in which the key is simply "error", the Error function is shorter and less repetitive.

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 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

Skip constructs a no-op field, which is often useful when handling invalid inputs in other Field constructors.

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 StackSkip

func StackSkip(key string, skip int) Field

StackSkip constructs a field similarly to Stack, but also skips the given number of frames from the top of the stacktrace.

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

Stringp constructs a field that carries a *string. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Timep constructs a field that carries a *time.Time. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Uint16p constructs a field that carries a *uint16. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Uint32p constructs a field that carries a *uint32. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Uint64p constructs a field that carries a *uint64. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Uint8p constructs a field that carries a *uint8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uintp

func Uintp(key string, val *uint) Field

Uintp constructs a field that carries a *uint. The returned Field will safely and explicitly represent `nil` when appropriate.

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

Uintptrp constructs a field that carries a *uintptr. The returned Field will safely and explicitly represent `nil` when appropriate.

type Level

type Level int8

A Level is a logging priority. Higher levels are more important.

const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel Level = iota - 1
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel

	DefaultAppShortName = "hello-world"
)

type LogInstance

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

type LoggingOption

type LoggingOption func(o *Options)

func WithProductNameShort

func WithProductNameShort(productNameShort string) LoggingOption

WithProductNameShort sets the name of your product used in log file names. example: logger.Instance().StartTask(logger.WithProductNameShort("your-product-name-here"))

func WithSampling

func WithSampling(samplingOptions SamplingOptions) LoggingOption

type Options

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

type SamplingOptions

type SamplingOptions struct {
	Tick       time.Duration
	First      int
	Thereafter int
}

type Singleton

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

func Instance

func Instance() *Singleton

func (*Singleton) AddLogger

func (s *Singleton) AddLogger(key string, w io.Writer, newLevel Level, opts ...LoggingOption)

func (*Singleton) DPanic

func (s *Singleton) DPanic(msg string, fields ...Field)

func (*Singleton) DPanicUnstruct deprecated

func (s *Singleton) DPanicUnstruct(args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) DPanicfUnstruct deprecated

func (s *Singleton) DPanicfUnstruct(format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) Debug

func (s *Singleton) Debug(msg string, fields ...Field)

func (*Singleton) DebugUnstruct deprecated

func (s *Singleton) DebugUnstruct(args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) DebugfUnstruct deprecated

func (s *Singleton) DebugfUnstruct(format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) Error

func (s *Singleton) Error(msg string, fields ...Field)

func (*Singleton) ErrorIgnoreCancel

func (s *Singleton) ErrorIgnoreCancel(ctx context.Context, msg string, fields ...Field)

func (*Singleton) ErrorIgnoreCancelUnstruct deprecated

func (s *Singleton) ErrorIgnoreCancelUnstruct(ctx context.Context, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) ErrorInLoggerWriter

func (s *Singleton) ErrorInLoggerWriter(format string, args ...interface{})

ErrorInLoggerWriter is used by log Writer sinks added with AddLogger() to log messages to standard console & file loggers that are enabled so the error in the logger can be trapped somewhere and without an error loop in the logger that triggered it

func (*Singleton) ErrorInLoggerWriterIgnoreCancel

func (s *Singleton) ErrorInLoggerWriterIgnoreCancel(ctx context.Context, format string, args ...interface{})

func (*Singleton) ErrorUnstruct deprecated

func (s *Singleton) ErrorUnstruct(args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) ErrorfIgnoreCancelUnstruct deprecated

func (s *Singleton) ErrorfIgnoreCancelUnstruct(ctx context.Context, format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) ErrorfUnstruct deprecated

func (s *Singleton) ErrorfUnstruct(format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) Fatal

func (s *Singleton) Fatal(msg string, fields ...Field)

func (*Singleton) FatalUnstruct deprecated

func (s *Singleton) FatalUnstruct(args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) FatalfUnstruct deprecated

func (s *Singleton) FatalfUnstruct(format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) Info

func (s *Singleton) Info(msg string, fields ...Field)

func (*Singleton) InfoIgnoreCancel

func (s *Singleton) InfoIgnoreCancel(ctx context.Context, msg string, fields ...Field)

func (*Singleton) InfoUnstruct deprecated

func (s *Singleton) InfoUnstruct(args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) InfofUnstruct deprecated

func (s *Singleton) InfofUnstruct(format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) IsLevelEnabled

func (s *Singleton) IsLevelEnabled(level Level) bool

func (*Singleton) Panic

func (s *Singleton) Panic(msg string, fields ...Field)

func (*Singleton) PanicUnstruct deprecated

func (s *Singleton) PanicUnstruct(args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) PanicfUnstruct deprecated

func (s *Singleton) PanicfUnstruct(format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) SetConsoleLogLevel

func (s *Singleton) SetConsoleLogLevel(newLevel Level)

func (*Singleton) SetConsoleLogging

func (s *Singleton) SetConsoleLogging(enabled bool)

func (*Singleton) SetFileLogLevel

func (s *Singleton) SetFileLogLevel(newLevel Level)

func (*Singleton) SetFileLogging

func (s *Singleton) SetFileLogging(enabled bool)

func (*Singleton) SetJsonStdoutLogLevel

func (s *Singleton) SetJsonStdoutLogLevel(newLevel Level)

func (*Singleton) SetJsonStdoutLogging

func (s *Singleton) SetJsonStdoutLogging(enabled bool)

func (*Singleton) SetLogLevel

func (s *Singleton) SetLogLevel(key string, newLevel Level)

func (*Singleton) SetLoggerEnabled

func (s *Singleton) SetLoggerEnabled(key string, enabled bool)

func (*Singleton) StartTask

func (s *Singleton) StartTask(opts ...LoggingOption)

func (*Singleton) StopTask

func (s *Singleton) StopTask()

func (*Singleton) Sync

func (s *Singleton) Sync()

func (*Singleton) Trace

func (s *Singleton) Trace(msg string, fields ...Field)

func (*Singleton) TraceUnstruct deprecated

func (s *Singleton) TraceUnstruct(args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) TracefUnstruct deprecated

func (s *Singleton) TracefUnstruct(format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) Warn

func (s *Singleton) Warn(msg string, fields ...Field)

func (*Singleton) WarnIgnoreCancel

func (s *Singleton) WarnIgnoreCancel(ctx context.Context, msg string, fields ...Field)

func (*Singleton) WarnIgnoreCancelUnstruct deprecated

func (s *Singleton) WarnIgnoreCancelUnstruct(ctx context.Context, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) WarnUnstruct deprecated

func (s *Singleton) WarnUnstruct(args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) WarnfIgnoreCancelUnstruct deprecated

func (s *Singleton) WarnfIgnoreCancelUnstruct(ctx context.Context, format string, args ...interface{})

Deprecated: use structured logging instead.

func (*Singleton) WarnfUnstruct deprecated

func (s *Singleton) WarnfUnstruct(format string, args ...interface{})

Deprecated: use structured logging instead.

Jump to

Keyboard shortcuts

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