logdash

package module
v0.0.0-...-5e087ad Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultBufferSize is the default size of the buffer for the async queue.
	DefaultBufferSize = 128
)
View Source
var ErrAlreadyClosed = errors.New("already closed or shutting down")

Functions

This section is empty.

Types

type Logdash

type Logdash struct {
	// Logger is the logger used to log messages to the Logdash server.
	//
	// If no API key is provided, the Logdash will not send any logs to the server.
	// Logging to the console is always enabled.
	Logger *Logger

	// Metrics is the metrics object used to track metrics.
	//
	// If no API key is provided, the Logdash will not send any metrics to the server.
	Metrics Metrics
	// contains filtered or unexported fields
}

Logdash is the main object exposing the Logdash API.

func New

func New(opts ...Option) *Logdash

New creates a new Logdash instance with the given options.

By default, the Logdash will use the Logdash API at https://api.logdash.io.

If no API key is provided, the Logdash will not send any logs or metrics to the server. Logging to the console is always enabled.

The default buffer size is 128 (see: DefaultBufferSize).

The default overflow policy is OverflowPolicyDrop, to avoid blocking the logging thread. For preserving logs in case of overflow, use WithOverflowPolicy to set OverflowPolicyBlock.

The default HTTP settings are:

func (*Logdash) Close

func (ld *Logdash) Close() error

func (*Logdash) Shutdown

func (ld *Logdash) Shutdown(ctx context.Context) error

type Logger

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

Logger is a struct that provides logging functionality.

This is created internally as a part of the Logdash object and accessed via the [Logdash.Logger] field.

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Debug

func (l *Logger) Debug(args ...any)

Debug logs a debug message.

func (*Logger) DebugF

func (l *Logger) DebugF(format string, args ...any)

DebugF logs a formatted debug message.

func (*Logger) Error

func (l *Logger) Error(args ...any)

Error logs an error message.

func (*Logger) ErrorF

func (l *Logger) ErrorF(format string, args ...any)

ErrorF logs a formatted error message.

func (*Logger) HTTP

func (l *Logger) HTTP(args ...any)

HTTP logs an HTTP-related message.

func (*Logger) HTTPF

func (l *Logger) HTTPF(format string, args ...any)

HTTPF logs a formatted HTTP-related message.

func (*Logger) Info

func (l *Logger) Info(args ...any)

Info logs an informational message.

func (*Logger) InfoF

func (l *Logger) InfoF(format string, args ...any)

InfoF logs a formatted informational message.

func (*Logger) Log

func (l *Logger) Log(args ...any)

Log is an alias for Info.

func (*Logger) LogF

func (l *Logger) LogF(format string, args ...any)

LogF is an alias for InfoF.

func (*Logger) Shutdown

func (l *Logger) Shutdown(ctx context.Context) error

func (*Logger) Silly

func (l *Logger) Silly(args ...any)

Silly logs a silly message (lowest priority).

func (*Logger) SillyF

func (l *Logger) SillyF(format string, args ...any)

SillyF logs a formatted silly message (lowest priority).

func (*Logger) Verbose

func (l *Logger) Verbose(args ...any)

Verbose logs a verbose message.

func (*Logger) VerboseF

func (l *Logger) VerboseF(format string, args ...any)

VerboseF logs a formatted verbose message.

func (*Logger) Warn

func (l *Logger) Warn(args ...any)

Warn logs a warning message.

func (*Logger) WarnF

func (l *Logger) WarnF(format string, args ...any)

WarnF logs a formatted warning message.

type Metrics

type Metrics interface {

	// Set sets a metric to an absolute value.
	Set(name string, value float64)

	// Mutate changes a metric by a relative value.
	Mutate(name string, value float64)
	// contains filtered or unexported methods
}

Metrics defines the interface for metrics functionality.

This is created internally as a part of the Logdash object and accessed via the [Logdash.Metrics] field.

type Option

type Option func(*options)

Option is a function that configures a Logdash instance.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for the Logdash server.

func WithBufferSize

func WithBufferSize(size int) Option

WithBufferSize sets the size of the buffer for the async queue.

func WithHTTPRetries

func WithHTTPRetries(retries int) Option

WithHTTPRetries sets the number of retries for HTTP requests.

func WithHTTPRetryMax

func WithHTTPRetryMax(max time.Duration) Option

WithHTTPRetryMax sets the maximum duration for HTTP retries.

func WithHTTPRetryMin

func WithHTTPRetryMin(min time.Duration) Option

WithHTTPRetryMin sets the minimum duration for HTTP retries.

func WithHTTPTimeout

func WithHTTPTimeout(timeout time.Duration) Option

WithHTTPTimeout sets the timeout for HTTP requests.

func WithHost

func WithHost(host string) Option

WithHost sets the host for the Logdash server.

func WithOverflowPolicy

func WithOverflowPolicy(policy OverflowPolicy) Option

WithOverflowPolicy sets how to handle log overflow.

func WithVerbose

func WithVerbose() Option

WithVerbose enables verbose logging.

This is useful for debugging, showing internal logs and changes in the metrics.

type OverflowPolicy

type OverflowPolicy int

OverflowPolicy defines how to handle log overflow.

const (
	// OverflowPolicyDrop drops new logs when the internal buffer is full.
	//
	// This is the default behavior.
	OverflowPolicyDrop OverflowPolicy = iota

	// OverflowPolicyBlock blocks when the internal buffer is full.
	//
	// This is useful when you want to preserve logs even when the internal buffer is full.
	OverflowPolicyBlock
)

type SlogTextHandler

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

SlogTextHandler is a slog.Handler that logs to Logdash.

It mimics slog.TextHandler behavior, but logs to Logdash instead of io.Writer.

slog.HandlerOptions are fully supported.

Basic mapping between slog.Level and [logdash.logLevel] is:

Since slog.Level is an integer type, the mapping handles any intermediate or custom level values:

If you want to log with a custom level, you can use slog.Level directly.

func NewSlogTextHandler

func NewSlogTextHandler(logger *Logger, opts slog.HandlerOptions) *SlogTextHandler

NewSlogTextHandler creates a new SlogTextHandler with the given Logger and slog.HandlerOptions.

func (*SlogTextHandler) Enabled

func (h *SlogTextHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*SlogTextHandler) Handle

func (h *SlogTextHandler) Handle(ctx context.Context, r slog.Record) error

func (*SlogTextHandler) WithAttrs

func (h *SlogTextHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SlogTextHandler) WithGroup

func (h *SlogTextHandler) WithGroup(name string) slog.Handler

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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