Documentation ¶
Overview ¶
Package logm implements a logging module.
Index ¶
- Constants
- func MustNewDefaultHoneycombSender(ctx context.Context) transmission.Sender
- func MustNewDefaultLogrusLogger(ctx context.Context) *logrus.Logger
- func NewInitializer(addClientFields func(context.Context, AddField)) injectz.Initializer
- func NewSingletonInjector(log RawLog) injectz.Injector
- func Wrap0(ctx context.Context, name string, f func(ctx context.Context) error, ...) error
- func Wrap0Panic(ctx context.Context, name string, f func(ctx context.Context) error, ...)
- func Wrap1[T any](ctx context.Context, name string, f func(ctx context.Context) (T, error), ...) (T, error)
- func Wrap1Panic[T any](ctx context.Context, name string, f func(ctx context.Context) (T, error), ...) T
- func Wrap2[T1 any, T2 any](ctx context.Context, name string, f func(ctx context.Context) (T1, T2, error), ...) (T1, T2, error)
- func Wrap2Panic[T1 any, T2 any](ctx context.Context, name string, f func(ctx context.Context) (T1, T2, error), ...) (T1, T2)
- func Wrap3[T1 any, T2 any, T3 any](ctx context.Context, name string, ...) (T1, T2, T3, error)
- func Wrap3Panic[T1 any, T2 any, T3 any](ctx context.Context, name string, ...) (T1, T2, T3)
- type AddField
- type BeginErrMetadata
- type BeginMetadata
- type BeginOption
- type BeginOptionFunc
- type EmitArgs
- type EmitMetadata
- type EmitOption
- type EmitOptionFunc
- type Log
- type LogConfig
- type LogConfigLogrusOutput
- type LogConfigMixin
- type RawLog
- type Sink
- type TraceLink
- type User
Constants ¶
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 ¶
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 ¶
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.
Types ¶
type BeginErrMetadata ¶
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 ¶
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 (BeginOptionFunc) Apply ¶
func (f BeginOptionFunc) Apply(o *beginOptions)
Apply implements the BeginOption interface.
type EmitMetadata ¶
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 (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).
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 ¶
GetLogConfig implements the LogConfigMixin interface.
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 ¶
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) SendResponse ¶
func (s *Sink) SendResponse(response transmission.Response) bool
SendResponse implements the transmission.Sender interface.
func (*Sink) TxResponses ¶
func (s *Sink) TxResponses() chan transmission.Response
TxResponses implements the transmission.Sender interface.
type TraceLink ¶
TraceLink describes a link annotation.
func MaybeParseTraceLink ¶
MaybeParseTraceLink parses a serialized *TraceLink.