logger

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 13 Imported by: 4

Documentation

Overview

Package logger defines how to log in trails as well as provide a default implementation of that interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithEnv added in v0.3.7

func WithEnv(env string) func(*TrailsLogger)

WithEnv sets the environment TrailsLogger is operating in.

func WithLevel added in v0.3.7

func WithLevel(level LogLevel) func(*TrailsLogger)

WithLevel sets the log level TrailsLogger uses.

func WithLogger added in v0.3.7

func WithLogger(log *log.Logger) func(*TrailsLogger)

WithLogger sets the log.Logger TrailsLogger uses.

Types

type LogContext added in v0.3.7

type LogContext struct {
	Data    map[string]interface{}
	Error   error
	Request *http.Request
	User    LogUser
}

func (LogContext) MarshalText added in v0.3.7

func (lc LogContext) MarshalText() ([]byte, error)

MarshalText converts LogContext into a JSON representation, eliminating zero-value fields.

Values in LogContext.Data that cannot be represented in JSON will cause an error to be thrown.

MarshalText implements encoding.TextMarshaler.

func (LogContext) String added in v0.3.7

func (lc LogContext) String() string

String stringifies LogContext as a JSON representation of it.

type LogLevel added in v0.3.7

type LogLevel int
const (
	LogLevelUnk LogLevel = iota
	LogLevelDebug
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelFatal
)

func NewLogLevel added in v0.3.7

func NewLogLevel(val string) LogLevel

func (LogLevel) String added in v0.3.7

func (ll LogLevel) String() string

type LogUser added in v0.3.7

type LogUser interface {
	GetID() uint
	GetEmail() string
}

type Logger

type Logger interface {
	Debug(msg string, ctx *LogContext)
	Error(msg string, ctx *LogContext)
	Fatal(msg string, ctx *LogContext)
	Info(msg string, ctx *LogContext)
	Warn(msg string, ctx *LogContext)

	LogLevel() LogLevel
}

The Logger interface defines the levels a logging can occur at.

func NewLogger added in v0.3.1

func NewLogger(opts ...LoggerOptFn) Logger

NewLogger constructs a TrailsLogger.

Logs are printed to os.Stdout by default, using the std lib log pkg. The default environment is DEVELOPMENT. The default log level is DEBUG.

func NewSentryLogger added in v0.3.7

func NewSentryLogger(tl *TrailsLogger, dsn string) Logger

NewSentryLogger constructs a SentryLogger based off the provided TrailsLogger.

type LoggerOptFn added in v0.3.7

type LoggerOptFn func(*TrailsLogger)

A LoggerOptFn is a functional option configuring a TrailsLogger when constructing a new one.

type SentryLogger added in v0.3.7

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

A SentryLogger

func (*SentryLogger) Debug added in v0.3.7

func (sl *SentryLogger) Debug(msg string, ctx *LogContext)

Debug writes a debug log.

func (*SentryLogger) Error added in v0.3.7

func (sl *SentryLogger) Error(msg string, ctx *LogContext)

Error writes an error log and sends it to Sentry.

func (*SentryLogger) Fatal added in v0.3.7

func (sl *SentryLogger) Fatal(msg string, ctx *LogContext)

Fatal writes a fatal log and sends it to Sentry.

func (*SentryLogger) Info added in v0.3.7

func (sl *SentryLogger) Info(msg string, ctx *LogContext)

Info writes an info log.

func (*SentryLogger) LogLevel added in v0.3.7

func (sl *SentryLogger) LogLevel() LogLevel

LogLevel returns the LogLevel set for the SentryLogger.

func (*SentryLogger) Warn added in v0.3.7

func (sl *SentryLogger) Warn(msg string, ctx *LogContext)

Warn writes a warning log and sends it to Sentry.

type TrailsLogger

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

TrailsLogger implements Logger using log.

func (*TrailsLogger) Debug

func (l *TrailsLogger) Debug(msg string, ctx *LogContext)

Debug writes a debug log.

func (*TrailsLogger) Error

func (l *TrailsLogger) Error(msg string, ctx *LogContext)

Error writes an error log.

func (*TrailsLogger) Fatal

func (l *TrailsLogger) Fatal(msg string, ctx *LogContext)

Fatal writes a fatal log.

func (*TrailsLogger) Info

func (l *TrailsLogger) Info(msg string, ctx *LogContext)

Info writes an info log.

func (*TrailsLogger) LogLevel added in v0.3.7

func (l *TrailsLogger) LogLevel() LogLevel

LogLevel returns the LogLevel set for the TrailsLogger.

func (*TrailsLogger) Warn

func (l *TrailsLogger) Warn(msg string, ctx *LogContext)

Warn writes a warning log.

Jump to

Keyboard shortcuts

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