logger

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoFlushWriter

type AutoFlushWriter struct {
	*bufio.Writer
}

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

func NewAutoFlushWriter

func NewAutoFlushWriter(w io.Writer) *AutoFlushWriter

NewAutoFlushWriter creates a new AutoFlushWriter.

func (*AutoFlushWriter) Write

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

Write writes the data and immediately flushes the buffer.

type JSONLoggerFactory

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 write to the single Writer, the rate-limited ones through a token bucket of their own.

func (*JSONLoggerFactory) GetLevel

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

GetLevel returns the log level string for the given scope.

func (*JSONLoggerFactory) NewLogger

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

func (s *JSONLoggerFactory) SetLevel(levelSpec string)

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

func (*JSONLoggerFactory) SetRateLimit

func (s *JSONLoggerFactory) SetRateLimit(limit rate.Limit, burst int, prefixes ...string)

SetRateLimit sets the rate limit of the loggers of the scopes starting with one of the prefixes, created after this call.

func (*JSONLoggerFactory) SetWriter

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

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

type LeveledLoggerFactory

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 write to the single Writer, the loggers of the rate-limited scopes through a token bucket of their own.

func (*LeveledLoggerFactory) GetLevel

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

GetLevel returns the log level string for the given scope.

func (*LeveledLoggerFactory) NewLogger

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

func (s *LeveledLoggerFactory) SetLevel(levelSpec string)

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

func (*LeveledLoggerFactory) SetRateLimit

func (s *LeveledLoggerFactory) SetRateLimit(limit rate.Limit, burst int, prefixes ...string)

SetRateLimit sets the rate limit of the loggers of the scopes starting with one of the prefixes, created after this call.

func (*LeveledLoggerFactory) SetWriter

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)
	// SetRateLimit limits the loggers of the scopes starting with one of the prefixes to limit
	// events per second at every level, with the given burst, each with a token bucket of its
	// own. Only affects loggers created after this call.
	SetRateLimit(limit rate.Limit, burst int, prefixes ...string)
}

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

func NewJSONLoggerFactory

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.

type Options

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 number of log events per second a rate-limited scope may log.
	// If non-positive, the caller should use its own default rate limit.
	RateLimit rate.Limit
	// Burst is the burst size of a rate-limited scope.
	// If non-positive, the caller should use its own default burst size.
	Burst int
	// Writer is the log output stream. If nil, the caller should use its own default
	// (os.Stderr).
	Writer io.Writer
}

Options configures logger behavior.

type RateLimitedWriter

type RateLimitedWriter struct {
	io.Writer
	*rate.Limiter
	// Counter counts the events suppressed since the last logged one.
	Counter       atomic.Int64
	AddSuppressed bool
}

RateLimitedWriter is a writer limited by a token bucket.

func NewRateLimitedWriter

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

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

Write fulfills io.Writer.

Jump to

Keyboard shortcuts

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