log

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrComponentFailure  = errors.New("failed to get caller information")
	ErrJSONIndentFailure = errors.New("failed to indent data into JSON")
	ErrJSONConversion    = errors.New("failed to convert input to JSON")
	ErrJSONUnmarshal     = errors.New("failed to unmarshal JSON")
	ErrUnexpectedType    = errors.New("unexpected data type after JSON conversion")
	ErrFieldTruncation   = errors.New("some fields were truncated")
)

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration dynamically chooses the best unit for logging.

func NewTool

func NewTool(c Client) *defaultTool

Types

type Blackbox

type Blackbox interface {
	// contains filtered or unexported methods
}

WARN: Methods from this interface require black-box testing because they internally call package-level functions (e.g., http.NewRequest) that are not easily mockable or stubbable. While we have access to their implementation, mocking or stubbing these functions is not practical. As a result, these methods are best tested using black-box testing techniques, such as input-based testing, where explicit error scenarios are triggered. Alternatively, these methods can also be tested using function variables.

type Client

type Client interface {
	Blackbox
	contract.Logger
}

func NewClient

func NewClient(out io.Writer, l slog.Level, opts LogOptions) Client

type Key

type Key = string
const (
	GoogleMessageKey   Key = "message"
	GoogleSeverityKey  Key = "severity"
	GoogleTimestampKey Key = "timestamp"
	GoogleComponentKey Key = "component"
)

type LogOption

type LogOption func(*LogOptions)

func WithLevelKey

func WithLevelKey(k Key) LogOption

func WithMaxLen

func WithMaxLen(maxLen uint) LogOption

func WithMessageKey

func WithMessageKey(k Key) LogOption

func WithTimeKey

func WithTimeKey(k Key) LogOption

type LogOptions

type LogOptions struct {
	Keys   map[string]string
	MaxLen uint
}

func ApplyLogOptions

func ApplyLogOptions(opts *LogOptions, modifiers ...LogOption) LogOptions

Jump to

Keyboard shortcuts

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