log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: Apache-2.0 Imports: 13 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustGetLogger

func MustGetLogger(name string, opts ...LoggerOption) (*zap.Logger, func())

MustGetLogger creates a named zap logger, typically to inject into a service runtime as the root logger.

This function returns a configured zap.Logger and a closing function to sync logs upon exit.

It panics upon failures, such as invalid log level, or incapacity to build the underlying logger.

func Requests

func Requests(lf Factory) func(http.Handler) http.Handler

Requests provides a middleware that logs http requests with a tracing-aware logger Factory.

Types

type Factory

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

Factory is the default logging wrapper that can create logger instances either contextless, or for a given context (e.g. to propagate trace spans).

A factory wraps a logger to propagate log entries as trace spans.

Loggers are zap structured loggers: see go.uber.org/zap.

func GetTestLoggerConfig

func GetTestLoggerConfig() (Factory, *zap.Logger, error)

GetTestLoggerConfig is intended to be used in test programs, and inject a logger factory or its underlying *zap.Logger into the tested components.

It is configurable from the "DEBUG_TEST" environment variable: if set, logging is enabled. Otherwise, logging is just muted, allowing to keep test verbosity low.

func MustGetTestLoggerConfig

func MustGetTestLoggerConfig() (Factory, *zap.Logger)

MustGetTestLoggerConfig is a wrapper around GetTestLoggerConfig that panics if an error is encountered.

func NewFactory

func NewFactory(logger *zap.Logger, opts ...Option) Factory

NewFactory creates a new logger Factory for an underlying zap logger.

func (Factory) Bg

func (b Factory) Bg() Logger

Bg creates a context-unaware logger, tied to the Background context.

func (Factory) For

func (b Factory) For(ctx context.Context) Logger

For returns a context-aware Logger.

If the context contains an OpenTracing span, all logging calls are also echo-ed to that span.

NOTE: for Datadog trace correlation, extra fields "dd.trace_id" and "dd.span_id" fields are added to the log entry.

func (Factory) With

func (b Factory) With(fields ...zapcore.Field) Factory

With creates a child logger and optionally adds some context fields to that logger.

func (Factory) WithZapOptions

func (b Factory) WithZapOptions(opts ...zap.Option) Factory

WithZapOptions creates a child logger with some zap.Option

type Logger

type Logger interface {
	Debug(msg string, fields ...zapcore.Field)
	Info(msg string, fields ...zapcore.Field)
	Warn(msg string, fields ...zapcore.Field)
	Error(msg string, fields ...zapcore.Field)
	Fatal(msg string, fields ...zapcore.Field)
	With(fields ...zapcore.Field) Logger
}

Logger is a simplified abstraction of the zap.Logger

type LoggerOption

type LoggerOption func(*loggerOptions)

LoggerOption sets options to tune the behavior of a logger.

func WithCallerSkip

func WithCallerSkip(skipped int) LoggerOption

WithCallerSkip sets the number of frames in the stack to skip.

By default, this is set to 1, so the logging function itself is skipped.

func WithDisableStackTrace

func WithDisableStackTrace(disabled bool) LoggerOption

WithDisableStackTrace disable stack printing for this logger

func WithLevel

func WithLevel(level string) LoggerOption

WithLevel sets the log level.

The level value must parse to a valid zapcore.Level, i.e. one of error, warn, info, debug values. The default level is "info".

type Option

type Option func(*options)

Option to build a logger factory.

func WithDatadog

func WithDatadog(enabled bool) Option

WithDatadog enables datadog-specific correlation fields to link logs to trace spans (requires to export all trace samples).

Directories

Path Synopsis
Package exporter provides extra trace span exporters, which may be added to some standard exporter such as jaeger or datadog.
Package exporter provides extra trace span exporters, which may be added to some standard exporter such as jaeger or datadog.
amplitude
Package amplitude exposes an exporter to route span traces to the Amplitude API.
Package amplitude exposes an exporter to route span traces to the Amplitude API.
influxdb
Package influxdb exposes an opencensus stats exporter for influxdb.
Package influxdb exposes an opencensus stats exporter for influxdb.
opentelemetry
Package opentelemetry should export traces produced by opencensus package to an opentelemetry backend.
Package opentelemetry should export traces produced by opencensus package to an opentelemetry backend.

Jump to

Keyboard shortcuts

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