logz

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initializer

func Initializer(ctx context.Context) (injectz.Injector, injectz.Releaser)

Initializer is a Logs initializer which provides a default implementation using Logrus and Sentry.

func NewConfigSingletonInjector

func NewConfigSingletonInjector(cfg *Config) injectz.Injector

NewConfigSingletonInjector always inject the given *Config.

func NewSingletonInjector

func NewSingletonInjector(l Logs) injectz.Injector

NewSingletonInjector always injects the given Logs.

Types

type Args

type Args []interface{}

Args describes a list of args used for formatting an entry message.

func A

func A(a ...interface{}) Args

A is a shorthand builder for args.

func (Args) Apply

func (a Args) Apply(_ *entry)

Apply implements the Option interface.

type BeforeSendFunc added in v1.0.0

type BeforeSendFunc func(event *sentry.Event, hint *sentry.EventHint) *sentry.Event

BeforeSendFunc describes a function called before sending out an event.

type Config added in v1.1.0

type Config struct {
	SentryLevel            Level            `json:"sentryLevel" validate:"required,oneof=debug info warning error"`
	OutputLevel            Level            `json:"outputLevel" validate:"required,oneof=debug info warning error"`
	OutputFormat           OutputFormat     `json:"format" validate:"required,oneof=text json"`
	SentryDSN              string           `json:"sentryDsn"`
	SentrySampleRate       float64          `json:"sentrySampleRate" validate:"required"`
	SentryTracesSampleRate float64          `json:"sentryTracesSampleRate" validate:"required"`
	SentryTransport        sentry.Transport `json:"-"`
	ReleaseTimeoutSeconds  int              `json:"releaseTimeoutSeconds"`
	Environment            string           `json:"environment"`
	Release                string           `json:"release"`
	ServerName             string           `json:"serverName"`
}

Config describes the configuration for Logs.

func (*Config) Validate added in v1.3.0

func (c *Config) Validate() error

Validate implements the vz.Validator interface.

type ContextLogs

type ContextLogs interface {
	Debug(format string, options ...Option)
	Info(format string, options ...Option)
	Warning(err error)
	Error(err error)
	TraceHTTPRequestServer(req *http.Request, reqBody []byte) (context.Context, func())
	TraceHTTPRequestServerSimple(req *sentry.Request) (context.Context, func())
	TraceSpan(op, desc string) (context.Context, func())
	SetUser(user *User)
	AddMetadata(k string, v interface{})
}

ContextLogs describes a Logs with a cached context.

func Get

func Get(ctx context.Context) ContextLogs

Get extracts the Logs from context and wraps it as ContextLogs, returns a no-op Logs if not found.

type Level

type Level string

Level describes a level.

const (
	Debug   Level = "debug"
	Info    Level = "info"
	Warning Level = "warning"
	Error   Level = "error"
)

Known levels.

type Logs

type Logs interface {
	Debug(ctx context.Context, skipCallers int, format string, options ...Option)
	Info(ctx context.Context, skipCallers int, format string, options ...Option)
	Warning(ctx context.Context, err error)
	Error(ctx context.Context, err error)
	TraceHTTPRequestServer(ctx context.Context, req *http.Request, reqBody []byte) (context.Context, func())
	TraceHTTPRequestServerSimple(ctx context.Context, req *sentry.Request) (context.Context, func())
	TraceSpan(ctx context.Context, op, desc string) (context.Context, func())
	SetUser(ctx context.Context, user *User)
	AddMetadata(ctx context.Context, k string, v interface{})
}

Logs describes the logs module.

type Metadata

type Metadata map[string]interface{}

Metadata describes metadata which can be attached to an entry.

func (Metadata) Apply

func (m Metadata) Apply(e *entry)

Apply implements the Option interface.

type Option

type Option interface {
	Apply(e *entry)
}

Option describes an option which can be applied to an entry.

type OptionFunc

type OptionFunc func(e *entry)

OptionFunc describes an option which can be applied to an entry.

func M

func M(k string, v interface{}) OptionFunc

M is a shorthand for providing metadata to an entry.

func (OptionFunc) Apply

func (f OptionFunc) Apply(e *entry)

Apply implements the Option interface.

type OutputFormat

type OutputFormat string

OutputFormat describes the format for output logs.

const (
	Text OutputFormat = "text"
	JSON OutputFormat = "json"
)

Known formats.

type User

type User struct {
	ID       string
	Email    string
	Metadata Metadata
}

User describes a user.

type UserExtractor

type UserExtractor interface {
	ExtractUser() *User
}

UserExtractor describes the ability to provide a user.

Directories

Path Synopsis
mocklogz
Package mocklogz is a generated GoMock package.
Package mocklogz is a generated GoMock package.

Jump to

Keyboard shortcuts

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