diag

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package diag provides basic utilities for troubleshooting application.

Available since v0.5.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter added in v0.7.0

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

Counter is a concurrency-safe struct that represents a single numerical value that can go up and go down. This implementation is optimized for a fast Inc/Dec/Add/Sub methods.

A Counter is typically used to count requests served, tasks completed, errors occurred, etc.

For Set-heavy use case. Please consider using Gauge instead.

Available since v0.7.0

func NewCounter added in v0.7.0

func NewCounter(initVal float64) *Counter

Return new Counter with the given initial value.

Available since v0.7.0

func (*Counter) Add added in v0.7.0

func (c *Counter) Add(v float64)

Add the given value to the counter.

Available since v0.7.0

func (*Counter) Dec added in v0.7.0

func (c *Counter) Dec()

Decrement the counter by 1.

Available since v0.7.0

func (*Counter) Inc added in v0.7.0

func (c *Counter) Inc()

Increment the counter by 1.

Available since v0.7.0

func (*Counter) Set added in v0.7.0

func (c *Counter) Set(v float64)

Set an arbitary value to the counter.

Available since v0.7.0

func (*Counter) Sub added in v0.7.0

func (c *Counter) Sub(v float64)

Subtract the given value to the counter.

Available since v0.7.0

func (*Counter) Value added in v0.7.0

func (c *Counter) Value() float64

Return the current value stored in the counter.

Available since v0.7.0

type DebugLogger added in v0.5.2

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

DebugLogger implement Logger interface that store log contents in a circular list.

Available since v0.5.2

func NewDebugLogger added in v0.5.2

func NewDebugLogger(capacity int) *DebugLogger

Return new DebugLogger with maximum capacity for cache.

Available since v0.5.2

func (*DebugLogger) All added in v0.5.2

func (l *DebugLogger) All() []*LogContext

Return the context for all log messages in chronological order.

Available since v0.5.2

func (*DebugLogger) AllMessages added in v0.5.2

func (l *DebugLogger) AllMessages() []string

Return the message for all log messages in chronological order.

Available since v0.5.2

func (*DebugLogger) AllMessagesReverse added in v0.5.2

func (l *DebugLogger) AllMessagesReverse() []string

Return the message for all log messages in reverse chronological order.

Available since v0.5.2

func (*DebugLogger) AllReverse added in v0.5.2

func (l *DebugLogger) AllReverse() []*LogContext

Return the context for all log messages in reverse chronological order.

Available since v0.5.2

func (DebugLogger) Debug added in v0.5.2

func (l DebugLogger) Debug(v ...interface{})

Print a message with Debug level.

Available since v0.5.2

func (DebugLogger) Debugf added in v0.5.2

func (l DebugLogger) Debugf(format string, v ...interface{})

Print a message with Debug level with format.

Available since v0.5.2

func (DebugLogger) Error added in v0.5.2

func (l DebugLogger) Error(err error, v ...interface{})

Print a message with Error level.

Available since v0.5.2

func (DebugLogger) Errorf added in v0.5.2

func (l DebugLogger) Errorf(err error, format string, v ...interface{})

Print a message with Error level with format.

Available since v0.5.2

func (DebugLogger) Info added in v0.5.2

func (l DebugLogger) Info(v ...interface{})

Print a message with Info level.

Available since v0.5.2

func (DebugLogger) Infof added in v0.5.2

func (l DebugLogger) Infof(format string, v ...interface{})

Print a message with Info level with format.

Available since v0.5.2

func (*DebugLogger) Last added in v0.5.2

func (l *DebugLogger) Last() *LogContext

Return the context for last log message.

Available since v0.5.2

func (*DebugLogger) LastMessage added in v0.5.2

func (l *DebugLogger) LastMessage() string

Return the message for last log message.

Available since v0.5.2

func (DebugLogger) Trace added in v0.5.2

func (l DebugLogger) Trace(v ...interface{})

Print a message with Trace level.

Available since v0.5.2

func (DebugLogger) Tracef added in v0.5.2

func (l DebugLogger) Tracef(format string, v ...interface{})

Print a message with Trace level with format.

Available since v0.5.2

func (DebugLogger) Warn added in v0.5.2

func (l DebugLogger) Warn(v ...interface{})

Print a message with Warn level.

Available since v0.5.2

func (DebugLogger) Warnf added in v0.5.2

func (l DebugLogger) Warnf(format string, v ...interface{})

Print a message with Warn level with format.

Available since v0.5.2

type DebugLoggerInternal added in v0.5.2

type DebugLoggerInternal struct {
	Cache *ring.Ring
	LogMu *sync.Mutex
}

DebugLoggerInternal stores internal data of a DebugLogger.

Available since v0.5.2

type DefaultLogger

type DefaultLogger struct {
}

DefaultLogger implement Logger interface that prints log message to stdout using global logger instance of Go.

Available since v0.5.0

func (DefaultLogger) Debug

func (l DefaultLogger) Debug(v ...interface{})

Print a message with Debug level.

Available since v0.5.0

func (DefaultLogger) Debugf

func (l DefaultLogger) Debugf(format string, v ...interface{})

Print a message with Debug level with format.

Available since v0.5.0

func (DefaultLogger) Error

func (l DefaultLogger) Error(err error, v ...interface{})

Print a message with Error level.

Available since v0.5.0

func (DefaultLogger) Errorf

func (l DefaultLogger) Errorf(err error, format string, v ...interface{})

Print a message with Error level with format.

Available since v0.5.0

func (DefaultLogger) Info

func (l DefaultLogger) Info(v ...interface{})

Print a message with Info level.

Available since v0.5.0

func (DefaultLogger) Infof

func (l DefaultLogger) Infof(format string, v ...interface{})

Print a message with Info level with format.

Available since v0.5.0

func (DefaultLogger) Trace

func (l DefaultLogger) Trace(v ...interface{})

Print a message with Trace level.

Available since v0.5.0

func (DefaultLogger) Tracef

func (l DefaultLogger) Tracef(format string, v ...interface{})

Print a message with Trace level with format.

Available since v0.5.0

func (DefaultLogger) Warn

func (l DefaultLogger) Warn(v ...interface{})

Print a message with Warn level.

Available since v0.5.0

func (DefaultLogger) Warnf

func (l DefaultLogger) Warnf(format string, v ...interface{})

Print a message with Warn level with format.

Available since v0.5.0

type Gauge added in v0.7.0

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

Gauge is a concurrency-safe struct that represents a single numerical value that can go up and go down. This implementation is optimized for a fast Set method.

A Gauge is typically used for measured values like temperatures or current memory usage, but also "counts" that can go up and down, like the number of running goroutines.

For Inc-heavy use case. Please consider using Counter instead.

Available since v0.7.0

func NewGauge added in v0.7.0

func NewGauge(initVal float64) *Gauge

Return new Counter with the given initial value.

Available since v0.7.0

func (*Gauge) Add added in v0.7.0

func (g *Gauge) Add(v float64)

Add the given value to the gauge.

Available since v0.7.0

func (*Gauge) Dec added in v0.7.0

func (g *Gauge) Dec()

Decrement the gauge by 1.

Available since v0.7.0

func (*Gauge) Inc added in v0.7.0

func (g *Gauge) Inc()

Increment the gauge by 1.

Available since v0.7.0

func (*Gauge) Set added in v0.7.0

func (g *Gauge) Set(v float64)

Set an arbitary value to the gauge.

Available since v0.7.0

func (*Gauge) Sub added in v0.7.0

func (g *Gauge) Sub(v float64)

Subtract the given value to the gauge.

Available since v0.7.0

func (*Gauge) Value added in v0.7.0

func (g *Gauge) Value() float64

Return the current value stored in the gauge.

Available since v0.7.0

type LogContext added in v0.5.2

type LogContext struct {
	Time    time.Time
	Level   LogLevel
	Message string
}

LogContext is a struct to store raw log message.

Available since v0.5.2

type LogLevel added in v0.5.2

type LogLevel int8

LogLevel indicates level of a log message.

Available since v0.5.2

const (
	NoLevel LogLevel = iota
	FatalLevel
	PanicLevel
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
	TraceLevel
)

type Logger

type Logger interface {
	// Print a message with Error level.
	Error(err error, v ...interface{})
	// Print a message with Error level with format.
	Errorf(err error, format string, v ...interface{})

	// Print a message with Warn level.
	Warn(v ...interface{})
	// Print a message with Warn level with format.
	Warnf(format string, v ...interface{})

	// Print a message with Info level.
	Info(v ...interface{})
	// Print a message with Info level with format.
	Infof(format string, v ...interface{})

	// Print a message with Debug level.
	Debug(v ...interface{})
	// Print a message with Debug level with format.
	Debugf(format string, v ...interface{})

	// Print a message with Trace level.
	Trace(v ...interface{})
	// Print a message with Trace level with format.
	Tracef(format string, v ...interface{})
}

Logger defines required function for all log levels used for application logging.

Available since v0.5.0

type Progress added in v0.7.0

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

Progress is a helper type to track progress.

Available since v0.7.0

func NewProgress added in v0.7.0

func NewProgress(total float64) *Progress

Return new Progress tracker with total items to complete.

Available since v0.7.0

func (*Progress) Add added in v0.7.0

func (p *Progress) Add(v float64)

Add v number of items as to be completed.

Available since v0.7.0

func (*Progress) Complete added in v0.7.0

func (p *Progress) Complete(v float64)

Mark v number of items as completed.

Available since v0.7.0

func (*Progress) EstimatedTime added in v0.7.0

func (p *Progress) EstimatedTime() time.Time

Estimate when the Progress will be completed.

Available since v0.7.0

func (*Progress) Percent added in v0.7.0

func (p *Progress) Percent() float64

func (*Progress) RemainTime added in v0.7.0

func (p *Progress) RemainTime() time.Duration

Estimate how long the Progress will be completed.

Available since v0.7.0

func (*Progress) Value added in v0.7.0

func (p *Progress) Value() (float64, float64, time.Time)

Return current value, total value and last updated time.

Available since v0.7.0

type Timer added in v0.7.0

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

Timer is a helper type to time functions.

Available since v0.7.0

func NewTimer added in v0.7.0

func NewTimer() *Timer

Return a new Timer starting from now.

Available since v0.7.0

func (*Timer) Duration added in v0.7.0

func (t *Timer) Duration() time.Duration

Return the duration since the Timer was created.

Available since v0.7.0

Jump to

Keyboard shortcuts

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