logger

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultRateLimit = rate.Limit(.25)
	DefaultBurstSize = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoFlushWriter added in v1.1.0

type AutoFlushWriter struct {
	*bufio.Writer
}

AutoFlushWriter wraps a bufio.Writer and ensures that Flush is called after every Write operation.

func NewAutoFlushWriter added in v1.1.0

func NewAutoFlushWriter(w io.Writer) *AutoFlushWriter

NewAutoFlushWriter creates a new AutoFlushWriter.

func (*AutoFlushWriter) Write added in v1.1.0

func (w *AutoFlushWriter) Write(p []byte) (n int, err error)

Write writes the data and immediately flushes the buffer.

type JSONLoggerFactory added in v1.2.0

type JSONLoggerFactory struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

JSONLoggerFactory wraps pion's JSON logger factory and satisfies STUNner's LoggerFactory interface (which adds SetLevel, GetLevel, and SetWriter on top of pion's NewLogger). Like LeveledLoggerFactory, all scopes share the single Writer.

func (*JSONLoggerFactory) GetLevel added in v1.2.0

func (s *JSONLoggerFactory) GetLevel(scope string) string

GetLevel returns the log level string for the given scope.

func (*JSONLoggerFactory) NewLogger added in v1.2.0

func (f *JSONLoggerFactory) NewLogger(scope string) logging.LeveledLogger

NewLogger returns (or creates) the JSON leveled logger for the given scope. The assertion l.(levelSetter) enforces that pion's JSON logger satisfies the registry contract; it panics at the first NewLogger call if the pion API ever changes.

func (*JSONLoggerFactory) SetLevel added in v1.2.0

func (s *JSONLoggerFactory) SetLevel(levelSpec string)

SetLevel applies a scoped level spec and propagates the new levels to all registered loggers.

func (*JSONLoggerFactory) SetWriter added in v1.2.0

func (f *JSONLoggerFactory) SetWriter(w io.Writer)

SetWriter sets the output writer. Only affects loggers created after this call.

type LeveledLoggerFactory added in v0.16.1

type LeveledLoggerFactory struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

LeveledLoggerFactory defines levels by scopes and creates new LeveledLoggers that can dynamically change their own loglevels. All loggers share the single Writer, so wrapping Writer with a RateLimitedWriter (via NewRateLimitedLoggerFactory) applies a single shared token bucket across all scopes.

func (*LeveledLoggerFactory) GetLevel added in v0.16.1

func (s *LeveledLoggerFactory) GetLevel(scope string) string

GetLevel returns the log level string for the given scope.

func (*LeveledLoggerFactory) NewLogger added in v0.16.1

func (f *LeveledLoggerFactory) NewLogger(scope string) logging.LeveledLogger

NewLogger either returns the existing LeveledLogger for the given scope or creates a new one.

func (*LeveledLoggerFactory) SetLevel added in v0.16.1

func (s *LeveledLoggerFactory) SetLevel(levelSpec string)

SetLevel applies a scoped level spec and propagates the new levels to all registered loggers.

func (*LeveledLoggerFactory) SetWriter added in v1.1.0

func (f *LeveledLoggerFactory) SetWriter(w io.Writer)

SetWriter sets the output writer. Only affects loggers created after this call.

type LoggerFactory

type LoggerFactory interface {
	logging.LoggerFactory
	// SetLevel sets the loglevel, optionally scoped (for example, "all:WARN,turn:DEBUG").
	SetLevel(levelSpec string)
	// GetLevel returns the loglevel for the given scope.
	GetLevel(scope string) string
	// SetWriter sets the output writer. Only affects loggers created after this call.
	SetWriter(w io.Writer)
}

LoggerFactory is the basic pion LoggerFactory interface extended with functions for setting and querying the loglevel per scope.

func NewJSONLoggerFactory added in v1.2.0

func NewJSONLoggerFactory(levelSpec string) LoggerFactory

NewJSONLoggerFactory creates a LoggerFactory that emits structured JSON log lines via pion/logging's slog-based JSON backend.

func NewLoggerFactory

func NewLoggerFactory(levelSpec string) LoggerFactory

NewLoggerFactory sets up a scoped logger for STUNner.

func NewRateLimitedLoggerFactory added in v1.1.0

func NewRateLimitedLoggerFactory(logger LoggerFactory, limit rate.Limit, burst int) LoggerFactory

NewRateLimitedLoggerFactory wraps the factory's current writer with a single shared rate-limiting token bucket. All log scopes and both backends share this bucket. Must be called before any loggers are created via NewLogger.

type Options added in v1.2.0

type Options struct {
	// Level is a scoped level specification (for example, "all:WARN,turn:DEBUG").
	// If empty, the caller should use its own default level.
	Level string
	// Format is the log output format: "text" (default) or "json".
	Format string
	// RateLimit is the maximum number of rate-limited log events per second.
	// If non-positive, the caller should use its own default rate limit.
	RateLimit rate.Limit
	// Burst is the burst size of the log rate limiter.
	// If non-positive, the caller should use its own default burst size.
	Burst int
}

Options configures logger behavior.

type RateLimitedWriter added in v0.16.1

type RateLimitedWriter struct {
	io.Writer
	*RateLimiter
	Counter       int
	AddSuppressed bool
}

RateLimitedWriter is a writer limited by a token bucket.

func NewRateLimitedWriter added in v0.16.1

func NewRateLimitedWriter(writer io.Writer, limit rate.Limit, burst int, addSuppressed bool) *RateLimitedWriter

NewRateLimitedWriter creates a writer rate-limited by a token bucket to at most limit events per second with the given burst size. If addSuppressed is true, the number of events suppressed between logged events is appended to the output.

func (*RateLimitedWriter) Write added in v0.16.1

func (w *RateLimitedWriter) Write(p []byte) (int, error)

Write fulfills io.Writer.

type RateLimiter added in v0.16.1

type RateLimiter struct {
	*rate.Limiter
	Enabled bool
}

RateLimiter is a token bucket that can be disabled.

func NewRateLimiter added in v0.16.1

func NewRateLimiter(r rate.Limit, b int) *RateLimiter

NewRateLimiter creates a new enabled rate limiter.

func (*RateLimiter) Allow added in v0.16.1

func (l *RateLimiter) Allow() bool

func (*RateLimiter) DisableRateLimiter added in v0.16.1

func (l *RateLimiter) DisableRateLimiter()

func (*RateLimiter) EnableRateLimiter added in v0.16.1

func (l *RateLimiter) EnableRateLimiter()

Jump to

Keyboard shortcuts

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