logger

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// OperationNameKey is the logging context key used for identifying name of an operation.
	OperationNameKey = "op_name"

	// OperationEventKey is the logging context key used for identifying a notable
	// event during the course of an operation.
	OperationEventKey = "op_event"

	// OperationElapsedKey is the logging context key used for identifying time elapsed to finish an operation.
	OperationElapsedKey = "op_elapsed"

	// DBInstanceKey is the logging context key used for identifying name of the relevant database.
	DBInstanceKey = "db_instance"

	// DBRetentionKey is the logging context key used for identifying name of the relevant retention policy.
	DBRetentionKey = "db_rp"

	// DBShardGroupKey is the logging context key used for identifying relevant shard group.
	DBShardGroupKey = "db_shard_group"

	// DBShardIDKey is the logging context key used for identifying name of the relevant shard number.
	DBShardIDKey = "db_shard_id"

	// TraceIDKey is the logging context key used for identifying the current trace.
	TraceIDKey = "ot_trace_id"

	// TraceSampledKey is the logging context key used for determining whether the current trace will be sampled.
	TraceSampledKey = "ot_trace_sampled"
)
View Source
const TimeFormat = "2006-01-02T15:04:05.000000Z07:00"

Variables

This section is empty.

Functions

func Database

func Database(name string) zapcore.Field

Database returns a field for tracking the name of a database.

func DurationLiteral

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

func IsTerminal

func IsTerminal(w io.Writer) bool

IsTerminal checks if w is a file and whether it is an interactive terminal session.

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *zap.Logger

LoggerFromContext returns the zap.Logger associated with ctx or nil if no logger has been assigned.

func NewContextWithLogger

func NewContextWithLogger(ctx context.Context, log *zap.Logger) context.Context

NewContextWithLogger returns a new context with log added.

func NewOperation

func NewOperation(ctx context.Context, log *zap.Logger, msg, name string, fields ...zapcore.Field) (*zap.Logger, func())

NewOperation uses the exiting log to create a new logger with context containing a trace id and the operation. Prior to returning, a standardized message is logged indicating the operation has started. The returned function should be called when the operation concludes in order to log a corresponding message which includes an elapsed time and that the operation has ended.

func OperationElapsed

func OperationElapsed(d time.Duration) zapcore.Field

OperationElapsed returns a field for tracking the duration of an operation.

func OperationEventEnd

func OperationEventEnd() zapcore.Field

OperationEventFinish returns a field for tracking the end of an operation.

func OperationEventStart

func OperationEventStart() zapcore.Field

OperationEventStart returns a field for tracking the start of an operation.

func OperationName

func OperationName(name string) zapcore.Field

OperationName returns a field for tracking the name of an operation.

func RetentionPolicy

func RetentionPolicy(name string) zapcore.Field

Database returns a field for tracking the name of a database.

func Shard

func Shard(id uint64) zapcore.Field

Shard returns a field for tracking the shard identifier.

func ShardGroup

func ShardGroup(id uint64) zapcore.Field

ShardGroup returns a field for tracking the shard group identifier.

func TraceFields

func TraceFields(ctx context.Context) []zap.Field

TraceFields returns a fields "ot_trace_id" and "ot_trace_sampled", values pulled from the (Jaeger) trace ID found in the given context. Returns nil if the context doesn't have a trace ID.

func TraceID

func TraceID(ctx context.Context) zap.Field

TraceID returns a field "trace_id", value pulled from the (Jaeger) trace ID found in the given context. Returns zap.Skip() if the context doesn't have a trace ID.

Types

type Config

type Config struct {
	Format       string               `toml:"format"`
	Level        zapcore.LevelEnabler `toml:"level"`
}

func NewConfig

func NewConfig() Config

NewConfig returns a new instance of Config with defaults.

func (*Config) New

func (c *Config) New(defaultOutput io.Writer) (*zap.Logger, error)

Jump to

Keyboard shortcuts

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