log

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package log provides logging utilities for S&D and makes it possible to hook into the logging to save the logs somewhere else.

Index

Constants

View Source
const (
	LevelError = Level("ERROR")
	LevelInfo  = Level("INFO")
)

Variables

This section is empty.

Functions

func AddHook

func AddHook(fn func(e Entry))

AddHook adds a hook that will be called with each log entry that gets created.

func Error

func Error(err error, values ...Value) error

Error logs the error with the given values and returns err as it was passed.

func ErrorString

func ErrorString(err string, values ...Value) error

ErrorString logs the error with the given values and returns a new err with string as it's content.

func ErrorUser

func ErrorUser(err error, userError string, values ...Value) error

ErrorUser logs the error with the given values and returns err as it is was passed if len(userError) == 0 or a new error with userError as content. This is useful if you want to return a more user-friendly error to the user while logging the original error in background.

func Info

func Info(text string, values ...Value)

Info logs a information with the given values.

func SetOutput

func SetOutput(writer io.Writer)

SetOutput changes the stream that the log's will be written to.

Types

type Entry

type Entry struct {
	Level  Level     `json:"level"`
	Time   time.Time `json:"time"`
	Text   string    `json:"text"`
	Caller string    `json:"caller"`
	Values []Value   `json:"values"`
}

Entry represents a single log entry.

type Level

type Level string

type Value

type Value struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Value represents a key, value pair containing contextual information for logging.

func WithValue

func WithValue(name string, value interface{}) Value

WithValue creates a named value that can be used to give a log contextual information.

Jump to

Keyboard shortcuts

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