log

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelTrace = "trace"
	LevelDebug = "debug"
	LevelInfo  = "info"
	LevelWarn  = "warn"
	LevelError = "error"

	PriorityTrace = 0
	PriorityDebug = 1
	PriorityInfo  = 2
	PriorityWarn  = 3
	PriorityError = 4
)
View Source
const MessageAttributeLoggerContext = "logger:context"

Variables

This section is empty.

Functions

func AddHandlerFactory

func AddHandlerFactory(typ string, factory HandlerFactory)

func AddHandlerIoWriterFactory

func AddHandlerIoWriterFactory(typ string, factory IoWriterWriterFactory)

func AppendLoggerContextField

func AppendLoggerContextField(ctx context.Context, fields map[string]interface{}) context.Context

AppendLoggerContextField appends the fields to the existing context fields, if there are no contextFields in the context then the value is initialized with the given fields. If there is a duplicate key then the newest value is the one that will be used.

func ContextLoggerFieldsResolver

func ContextLoggerFieldsResolver(ctx context.Context) map[string]interface{}

ContextLoggerFieldsResolver extracts the ContextFields from ctx, if not present returns empty ContextFields

func FormatterConsole

func FormatterConsole(timestamp string, level int, format string, args []interface{}, err error, data Data) ([]byte, error)

func FormatterJson

func FormatterJson(timestamp string, level int, format string, args []interface{}, err error, data Data) ([]byte, error)

func GetMockedStackTrace

func GetMockedStackTrace(depthSkip int) string

func GetStackTrace

func GetStackTrace(depthSkip int) string

GetStackTrace constructs the current stacktrace. depthSkip defines how many steps of the stacktrace should be skipped. This is useful to not clutter the stacktrace with logging function calls.

func LevelName

func LevelName(level int) string

func LevelPriority

func LevelPriority(level string) int

func MainLoggerConfigPostProcessor

func MainLoggerConfigPostProcessor(config cfg.GosoConf) (bool, error)

func NewHandlerIoWriter

func NewHandlerIoWriter(level string, channels []string, formatter Formatter, timestampFormat string, writer io.Writer) *handlerIoWriter

func NewIoWriterFile

func NewIoWriterFile(path string) (io.Writer, error)

func NewLogger

func NewLogger() *gosoLogger

func NewLoggerContext

func NewLoggerContext(ctx context.Context, fields map[string]interface{}) context.Context

NewLoggerContext returns a new Context carrying fields

func NewLoggerWithInterfaces

func NewLoggerWithInterfaces(clock clock.Clock, handlers []Handler) *gosoLogger

func SentryContextConfigProvider

func SentryContextConfigProvider(config ConfigProvider, handler *HandlerSentry) error

func SentryContextEcsMetadataProvider

func SentryContextEcsMetadataProvider(_ ConfigProvider, handler *HandlerSentry) error

func UnmarshalHandlerSettingsFromConfig

func UnmarshalHandlerSettingsFromConfig(config cfg.Config, name string, settings interface{})

Types

type ConfigProvider

type ConfigProvider interface {
	AllSettings() map[string]interface{}
}

type ContextEnforcingLogger

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

func NewContextEnforcingLogger

func NewContextEnforcingLogger(logger Logger) *ContextEnforcingLogger

func NewContextEnforcingLoggerWithInterfaces

func NewContextEnforcingLoggerWithInterfaces(logger Logger, stacktraceProvider StackTraceProvider, notifier Logger) *ContextEnforcingLogger

func (*ContextEnforcingLogger) Debug

func (l *ContextEnforcingLogger) Debug(msg string, args ...interface{})

func (*ContextEnforcingLogger) Enable

func (l *ContextEnforcingLogger) Enable()

func (*ContextEnforcingLogger) Error

func (l *ContextEnforcingLogger) Error(msg string, args ...interface{})

func (*ContextEnforcingLogger) Info

func (l *ContextEnforcingLogger) Info(msg string, args ...interface{})

func (*ContextEnforcingLogger) Warn

func (l *ContextEnforcingLogger) Warn(msg string, args ...interface{})

func (*ContextEnforcingLogger) WithChannel

func (l *ContextEnforcingLogger) WithChannel(channel string) Logger

func (*ContextEnforcingLogger) WithContext

func (l *ContextEnforcingLogger) WithContext(ctx context.Context) Logger

func (*ContextEnforcingLogger) WithFields

func (l *ContextEnforcingLogger) WithFields(fields Fields) Logger

type ContextFieldsResolver

type ContextFieldsResolver func(ctx context.Context) map[string]interface{}

type Data

type Data struct {
	Context       context.Context
	Channel       string
	ContextFields map[string]interface{}
	Fields        map[string]interface{}
}

type EcsMetadata

type EcsMetadata map[string]interface{}

func ReadEcsMetadata

func ReadEcsMetadata() (EcsMetadata, error)

type Fields

type Fields map[string]interface{}

type Formatter

type Formatter func(timestamp string, level int, format string, args []interface{}, err error, data Data) ([]byte, error)

type GosoLogger

type GosoLogger interface {
	Logger
	Option(opt ...Option) error
}

type Handler

type Handler interface {
	Channels() []string
	Level() int
	Log(timestamp time.Time, level int, msg string, args []interface{}, err error, data Data) error
}

func NewCliHandler

func NewCliHandler() Handler

func NewHandlersFromConfig

func NewHandlersFromConfig(config cfg.Config) ([]Handler, error)

type HandlerFactory

type HandlerFactory func(config cfg.Config, name string) (Handler, error)

type HandlerIoWriterSettings

type HandlerIoWriterSettings struct {
	Level           string   `cfg:"level" default:"info"`
	Channels        []string `cfg:"channels"`
	Formatter       string   `cfg:"formatter" default:"console"`
	TimestampFormat string   `cfg:"timestamp_format" default:"15:04:05.000"`
	Writer          string   `cfg:"writer" default:"stdout"`
}

type HandlerSentry

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

func NewHandlerSentry

func NewHandlerSentry(config cfg.Config) (*HandlerSentry, error)

func (*HandlerSentry) Channels

func (h *HandlerSentry) Channels() []string

func (*HandlerSentry) Level

func (h *HandlerSentry) Level() int

func (*HandlerSentry) Log

func (h *HandlerSentry) Log(_ time.Time, _ int, _ string, _ []interface{}, err error, data Data) error

func (*HandlerSentry) WithContext

func (h *HandlerSentry) WithContext(name string, context map[string]interface{})

type HandlerSettings

type HandlerSettings struct {
	Type string `cfg:"type"`
}

type IoWriterWriterFactory

type IoWriterWriterFactory func(config cfg.Config, configKey string) (io.Writer, error)

type Logger

type Logger interface {
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warn(format string, args ...interface{})
	Error(format string, args ...interface{})

	WithChannel(channel string) Logger
	WithContext(ctx context.Context) Logger
	WithFields(Fields) Logger
}

func NewCliLogger

func NewCliLogger() Logger

func NewSamplingLogger

func NewSamplingLogger(logger Logger, interval time.Duration) Logger

type LoggerSettings

type LoggerSettings struct {
	Handlers map[string]HandlerSettings `cfg:"handlers"`
}

type MessageWithLoggingFieldsEncoder

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

func NewMessageWithLoggingFieldsEncoder

func NewMessageWithLoggingFieldsEncoder(_ cfg.Config, logger Logger) *MessageWithLoggingFieldsEncoder

func NewMessageWithLoggingFieldsEncoderWithInterfaces

func NewMessageWithLoggingFieldsEncoderWithInterfaces(logger Logger) *MessageWithLoggingFieldsEncoder

func (MessageWithLoggingFieldsEncoder) Decode

func (m MessageWithLoggingFieldsEncoder) Decode(ctx context.Context, _ interface{}, attributes map[string]interface{}) (context.Context, map[string]interface{}, error)

func (MessageWithLoggingFieldsEncoder) Encode

func (m MessageWithLoggingFieldsEncoder) Encode(ctx context.Context, _ interface{}, attributes map[string]interface{}) (context.Context, map[string]interface{}, error)

type Option

type Option func(logger *gosoLogger) error

func WithContextFieldsResolver

func WithContextFieldsResolver(resolvers ...ContextFieldsResolver) Option

func WithFields

func WithFields(tags map[string]interface{}) Option

func WithHandlers

func WithHandlers(handler ...Handler) Option

type SamplingLogger

type SamplingLogger struct {
	Logger
	// contains filtered or unexported fields
}

func NewSamplingLoggerWithInterfaces

func NewSamplingLoggerWithInterfaces(logger Logger, clock clock.Clock, interval time.Duration) *SamplingLogger

func (*SamplingLogger) Debug

func (l *SamplingLogger) Debug(msg string, args ...interface{})

func (*SamplingLogger) Error

func (l *SamplingLogger) Error(msg string, args ...interface{})

func (*SamplingLogger) Info

func (l *SamplingLogger) Info(msg string, args ...interface{})

func (*SamplingLogger) Warn

func (l *SamplingLogger) Warn(msg string, args ...interface{})

func (*SamplingLogger) WithChannel

func (l *SamplingLogger) WithChannel(channel string) Logger

func (*SamplingLogger) WithContext

func (l *SamplingLogger) WithContext(ctx context.Context) Logger

func (*SamplingLogger) WithFields

func (l *SamplingLogger) WithFields(fields Fields) Logger

type SentryContextProvider

type SentryContextProvider func(config ConfigProvider, sentryHook *HandlerSentry) error

type SentryHub

type SentryHub interface {
	ConfigureScope(f func(scope *sentry.Scope))
	WithScope(f func(scope *sentry.Scope))
	CaptureException(exception error) *sentry.EventID
	Flush(timeout time.Duration) bool
}

func NewSentryHub

func NewSentryHub(config cfg.Config) (SentryHub, error)

func NewSentryHubWithSettings

func NewSentryHubWithSettings(settings *SentryHubSettings) (SentryHub, error)

type SentryHubSettings

type SentryHubSettings struct {
	Dsn         string
	Environment string
	AppName     string
}

type StackTraceProvider

type StackTraceProvider func(depthSkip int) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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