log

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextKeyValues

func ContextKeyValues(ctx context.Context) []models.KeyValue

ContextKeyValues returns the list of jettison key values options contained in the given context.

func ContextWith

func ContextWith(ctx context.Context, opts ...ContextOption) context.Context

ContextWith returns a new context with the given jettison options appended to its key/value store. When a context containing jettison options is passed to Info or Error, the options are automatically applied to the resulting log.

func ContextWithKeyValues

func ContextWithKeyValues(ctx context.Context, add []models.KeyValue) context.Context

func Debug

func Debug(ctx context.Context, msg string, opts ...Option)

func Error

func Error(ctx context.Context, err error, opts ...Option)

Error writes a structured jettison log of the given error to the logger. If the error is not already a Jettison error, it is converted into one and then logged. Any jettison key/value pairs contained in the given context are included in the log. If err is nil, a new error is created.

func Fatal

func Fatal(v ...interface{})

Fatal is equivalent to log.Print followed by a call to os.Exit(1). Deprecated: Use log.Info or log.Error instead and exit manually.

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf is equivalent to log.Printf followed by a call to os.Exit(1). Deprecated: Use log.Info or log.Error instead and exit manually.

func Fatalln

func Fatalln(v ...interface{})

Fatalln is equivalent to log.Println followed by a call to os.Exit(1). Deprecated: Use log.Info or log.Error instead and exit manually.

func Info

func Info(ctx context.Context, msg string, opts ...Option)

Info writes a structured jettison log to the logger. Any jettison key/value pairs contained in the given context are included in the log.

func Panic

func Panic(v ...interface{})

Panic is equivalent to log.Print followed by a panic. Deprecated: Use log.Info or log.Error instead and panic manually.

func Panicf

func Panicf(format string, v ...interface{})

Panicf is equivalent to log.Printf followed by a panic. Deprecated: Use log.Info or log.Error instead and panic manually.

func Panicln

func Panicln(v ...interface{})

Panicln is equivalent to log.Println followed by a panic. Deprecated: Use log.Info or log.Error instead and panic manually.

func Print

func Print(v ...interface{})

Print wraps a call to fmt.Sprint in a jettison log and writes it to the logger. Deprecated: Use log.Info or log.Error instead.

func Printf

func Printf(format string, v ...interface{})

Printf wraps a call to fmt.Sprintf in a jettison log and writes it to the logger. Deprecated: Use log.Info or log.Error instead.

func Println

func Println(v ...interface{})

Println wraps a call to fmt.Sprintln in a jettison log and writes it to the logger. Deprecated: Use log.Info or log.Error instead.

func SetCmdLoggerForTesting

func SetCmdLoggerForTesting(t testing.TB, w io.Writer)

func SetDefaultLoggerForTesting

func SetDefaultLoggerForTesting(t testing.TB, w io.Writer, opts ...Option)

func SetLogger

func SetLogger(l Logger)

SetLogger sets the global logger.

func SetLoggerForTesting

func SetLoggerForTesting(t testing.TB, l Logger)

Types

type CmdLogger

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

func NewCmdLogger

func NewCmdLogger(w io.Writer, stripTime bool) *CmdLogger

NewCmdLogger returns a stdout human friendly command line logger.

func (*CmdLogger) Log

func (c *CmdLogger) Log(_ context.Context, l Entry) string

type ContextOption

type ContextOption interface {
	ContextKeys() []models.KeyValue
}

ContextOption allows us to use the same type as an option for ContextWith as well as other jettison interfaces.

type ElasticStringArray

type ElasticStringArray []struct {
	Content []string `json:">"`
}

ElasticStringArray is a converted type that stops ElasticSearch from joining elements of the string slice with commas

func MakeElastic

func MakeElastic(s []string) ElasticStringArray

func (ElasticStringArray) Content

func (e ElasticStringArray) Content() []string

type Entry

type Entry struct {
	Message   string    `json:"message"`
	Source    string    `json:"source"`
	Level     Level     `json:"level"`
	Timestamp time.Time `json:"timestamp"`

	Parameters []models.KeyValue `json:"parameters,omitempty"`
	ErrorCode  *string           `json:"error_code,omitempty"`

	ErrorObject  *ErrorObject  `json:"error_object,omitempty"`
	ErrorObjects []ErrorObject `json:"error_objects,omitempty"`
}

func (*Entry) SetKey

func (l *Entry) SetKey(key, value string)

SetKey updates the list of parameters in the log with the given key/value pair.

func (*Entry) SetSource

func (l *Entry) SetSource(src string)

SetSource updates the source of the log.

type ErrorObject

type ErrorObject struct {
	Code       string             `json:"code"`
	Source     string             `json:"source"`
	Message    string             `json:"message"`
	Stack      []string           `json:"stack,omitempty"`
	StackTrace ElasticStringArray `json:"stacktrace,omitempty"`
	Parameters []models.KeyValue  `json:"parameters,omitempty"`
}

type Interface

type Interface interface {
	Debug(ctx context.Context, msg string, ol ...Option)
	Info(ctx context.Context, msg string, ol ...Option)
	Error(ctx context.Context, err error, ol ...Option)
}

type Jettison

type Jettison struct{}

func (Jettison) Debug

func (j Jettison) Debug(ctx context.Context, msg string, ol ...Option)

func (Jettison) Error

func (j Jettison) Error(ctx context.Context, err error, ol ...Option)

func (Jettison) Info

func (j Jettison) Info(ctx context.Context, msg string, ol ...Option)

type Level

type Level string
const (
	LevelInfo  Level = "info"
	LevelError Level = "error"
	LevelDebug Level = "debug"
)

type Logger

type Logger interface {
	// Log logs the given log and returns a string of what was written.
	Log(context.Context, Entry) string
}

Logger does logging of log lines.

type Option

type Option interface {
	ApplyToLog(*Entry)
}

func WithError

func WithError(err error) Option

WithError returns a jettison option to add a structured error as part of Info logging. See Error for more details. It only works when provided as option to log package functions. Using this option while Error logging is not recommended.

func WithLevel

func WithLevel(level Level) Option

WithLevel returns a jettison option to override the default log level. It only works when provided as option to log package functions.

Jump to

Keyboard shortcuts

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