logm

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package logm implements a logging module.

Index

Constants

View Source
const (
	StandardKeyParams          = "params"
	StandardKeySecondaryParams = "secondaryParams"
)

Some commonly used field keys.

Variables

This section is empty.

Functions

func MustNewDefaultHoneycombSender

func MustNewDefaultHoneycombSender(ctx context.Context) transmission.Sender

MustNewDefaultHoneycombSender initializes a default transmission.Sender using the LogConfigMixin from context.

func MustNewDefaultLogrusLogger

func MustNewDefaultLogrusLogger(ctx context.Context) *logrus.Logger

MustNewDefaultLogrusLogger initializes a default *logrus.Logger using the LogConfigMixin from context.

func NewInitializer

func NewInitializer(addClientFields func(context.Context, AddField)) injectz.Initializer

NewInitializer returns a new injectz.Initializer that configures the given client-level fields.

func NewSingletonInjector

func NewSingletonInjector(log RawLog) injectz.Injector

NewSingletonInjector injects.

func Wrap0

func Wrap0(
	ctx context.Context,
	name string,
	f func(ctx context.Context) error,
	options ...BeginOption) error

Wrap0 traces a function that returns (error).

func Wrap0Panic

func Wrap0Panic(
	ctx context.Context,
	name string,
	f func(ctx context.Context) error,
	options ...BeginOption)

Wrap0Panic traces a function that returns (error). It panics if the returned error is non-nil.

func Wrap1

func Wrap1[T any](
	ctx context.Context,
	name string,
	f func(ctx context.Context) (T, error),
	options ...BeginOption) (T, error)

Wrap1 traces a function that returns (T, error).

func Wrap1Panic

func Wrap1Panic[T any](
	ctx context.Context,
	name string,
	f func(ctx context.Context) (T, error),
	options ...BeginOption) T

Wrap1Panic traces a function that returns (T, error). It panics if the returned error is non-nil.

func Wrap2

func Wrap2[T1 any, T2 any](
	ctx context.Context,
	name string,
	f func(ctx context.Context) (T1, T2, error),
	options ...BeginOption) (T1, T2, error)

Wrap2 traces a function that returns (T1, T2, error).

func Wrap2Panic

func Wrap2Panic[T1 any, T2 any](
	ctx context.Context,
	name string,
	f func(ctx context.Context) (T1, T2, error),
	options ...BeginOption) (T1, T2)

Wrap2Panic traces a function that returns (T1, T2, error). It panics if the returned error is non-nil.

func Wrap3

func Wrap3[T1 any, T2 any, T3 any](
	ctx context.Context,
	name string,
	f func(ctx context.Context) (T1, T2, T3, error),
	options ...BeginOption) (T1, T2, T3, error)

Wrap3 traces a function that returns (T1, T2, T2, error).

func Wrap3Panic

func Wrap3Panic[T1 any, T2 any, T3 any](
	ctx context.Context,
	name string,
	f func(ctx context.Context) (T1, T2, T3, error),
	options ...BeginOption) (T1, T2, T3)

Wrap3Panic traces a function that returns (T1, T2, T2, error). It panics if the returned error is non-nil.

Types

type AddField added in v0.3.0

type AddField interface {
	AddField(string, any)
}

AddField describes the ability to add fields to an event.

type BeginErrMetadata

type BeginErrMetadata map[string]any

BeginErrMetadata describes metadata that is applied only in error cases.

func (BeginErrMetadata) Apply

func (m BeginErrMetadata) Apply(o *beginOptions)

Apply implements the BeginOption interface.

type BeginMetadata

type BeginMetadata map[string]any

BeginMetadata describes metadata.

func (BeginMetadata) Apply

func (m BeginMetadata) Apply(o *beginOptions)

Apply implements the BeginOption interface.

type BeginOption

type BeginOption interface {
	Apply(o *beginOptions)
}

BeginOption describes an option.

type BeginOptionFunc

type BeginOptionFunc func(o *beginOptions)

BeginOptionFunc is a shorthand for BeginOption.

func BeginErrM

func BeginErrM(k string, v any) BeginOptionFunc

BeginErrM is a shorthand for BeginErrMetadata.

func BeginM

func BeginM(k string, v any) BeginOptionFunc

BeginM is a shorthand for BeginMetadata.

func (BeginOptionFunc) Apply

func (f BeginOptionFunc) Apply(o *beginOptions)

Apply implements the BeginOption interface.

type EmitArgs

type EmitArgs []any

EmitArgs describes a list of args.

func EmitA

func EmitA(a ...any) EmitArgs

EmitA is a shorthand for EmitArgs.

func (EmitArgs) Apply

func (a EmitArgs) Apply(o *emitOptions)

Apply implements the EmitOption interface.

type EmitMetadata

type EmitMetadata map[string]any

EmitMetadata describes metadata.

func (EmitMetadata) Apply

func (m EmitMetadata) Apply(o *emitOptions)

Apply implements the EmitOption interface.

type EmitOption

type EmitOption interface {
	Apply(o *emitOptions)
}

EmitOption describes an option.

type EmitOptionFunc

type EmitOptionFunc func(o *emitOptions)

EmitOptionFunc is a shorthand for EmitOption.

func EmitM

func EmitM(k string, v any) EmitOptionFunc

EmitM is a shorthand for EmitMetadata.

func (EmitOptionFunc) Apply

func (f EmitOptionFunc) Apply(o *emitOptions)

Apply implements the EmitOption interface.

type Log

type Log interface {
	EmitDebug(format string, options ...EmitOption)
	EmitInfo(format string, options ...EmitOption)
	EmitWarning(err error)
	EmitError(err error)
	EmitTraceLink(traceLink *TraceLink)
	Begin(name string, options ...BeginOption) (context.Context, func())
	SetUser(user *User)
	SetPropagatingField(k string, v any)
	SetMetadataKey(k string, v any)
	SetErrorMetadataKey(k string, v any)
	SetErrorFlag()
	GetCurrentTraceLink() *TraceLink
	Flush()
}

Log describes the module (with cached context).

func MustGet

func MustGet(ctx context.Context) Log

MustGet extracts, panics if not found.

type LogConfig

type LogConfig struct {
	HoneycombAPIKey     string                `env:"LOG_HONEYCOMB_API_KEY,required"`
	HoneycombDataset    string                `env:"LOG_HONEYCOMB_DATASET,required"`
	HoneycombSampleRate uint                  `env:"LOG_HONEYCOMB_SAMPLE_RATE,required" validate:"required,min=1"`
	LogrusOutput        LogConfigLogrusOutput `env:"LOG_LOGRUS_OUTPUT,required"`
	LogrusLevel         logrus.Level          `env:"LOG_LOGRUS_LEVEL,required"`
}

LogConfig describes the module configuration.

func (*LogConfig) Config

func (c *LogConfig) Config()

Config implements the cfgm.Config interface.

func (*LogConfig) GetLogConfig

func (c *LogConfig) GetLogConfig() *LogConfig

GetLogConfig implements the LogConfigMixin interface.

func (*LogConfig) ToEnv added in v0.3.0

func (c *LogConfig) ToEnv(prefix string) map[string]string

ToEnv converts the config to an env map.

type LogConfigLogrusOutput

type LogConfigLogrusOutput string

LogConfigLogrusOutput describes the acceptable values for [LogConfig.LogrusOutput].

const (
	LogConfigLogrusOutputDisabled LogConfigLogrusOutput = cfgm.DisabledValue
	LogConfigLogrusOutputHuman    LogConfigLogrusOutput = "human"
	LogConfigLogrusOutputJSON     LogConfigLogrusOutput = "json"
)

Known LogConfigLogrusOutput values.

func (*LogConfigLogrusOutput) String added in v0.3.0

func (l *LogConfigLogrusOutput) String() string

String implements the fmt.Stringer interface.

func (*LogConfigLogrusOutput) UnmarshalText

func (l *LogConfigLogrusOutput) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type LogConfigMixin

type LogConfigMixin interface {
	cfgm.Config
	GetLogConfig() *LogConfig
}

LogConfigMixin describes the module configuration.

type RawLog

type RawLog interface {
	EmitDebug(ctx context.Context, format string, options ...EmitOption)
	EmitInfo(ctx context.Context, format string, options ...EmitOption)
	EmitWarning(ctx context.Context, err error)
	EmitError(ctx context.Context, err error)
	EmitTraceLink(ctx context.Context, linkAnnotation *TraceLink)
	Begin(ctx context.Context, name string, options ...BeginOption) (context.Context, func())
	SetErrorFlag(ctx context.Context)
	SetUser(ctx context.Context, user *User)
	SetPropagatingField(ctx context.Context, k string, v any)
	SetMetadataKey(ctx context.Context, k string, v any)
	SetErrorMetadataKey(ctx context.Context, k string, v any)
	GetCurrentTraceLink(ctx context.Context) *TraceLink
	Flush(ctx context.Context)
}

RawLog describes the module.

func NewRawLogFromClient

func NewRawLogFromClient(client *libhoney.Client) RawLog

NewRawLogFromClient initializes a new RawLog using the given *libhoney.Client.

type Sink

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

Sink describes a sink.

func NewSink

func NewSink(logger *logrus.Logger, sender transmission.Sender) *Sink

NewSink initializes a new *Sink.

func (*Sink) Add

func (s *Sink) Add(e *transmission.Event)

Add implements the transmission.Sender interface.

func (*Sink) Flush

func (s *Sink) Flush() error

Flush implements the transmission.Sender interface.

func (*Sink) SendResponse

func (s *Sink) SendResponse(response transmission.Response) bool

SendResponse implements the transmission.Sender interface.

func (*Sink) Start

func (s *Sink) Start() error

Start implements the transmission.Sender interface.

func (*Sink) Stop

func (s *Sink) Stop() error

Stop implements the transmission.Sender interface.

func (*Sink) TxResponses

func (s *Sink) TxResponses() chan transmission.Response

TxResponses implements the transmission.Sender interface.

type TraceLink struct {
	TraceID string
	SpanID  string
}

TraceLink describes a link annotation.

func MaybeParseTraceLink(traceLink string) *TraceLink

MaybeParseTraceLink parses a serialized *TraceLink.

func (*TraceLink) Serialize

func (l *TraceLink) Serialize() string

Serialize the *TraceLink.

type User

type User struct {
	ID    string
	Email string
}

User describes a user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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