Documentation
¶
Index ¶
- type AutoFlushWriter
- type JSONLoggerFactory
- func (s *JSONLoggerFactory) GetLevel(scope string) string
- func (f *JSONLoggerFactory) NewLogger(scope string) logging.LeveledLogger
- func (s *JSONLoggerFactory) SetLevel(levelSpec string)
- func (s *JSONLoggerFactory) SetRateLimit(limit rate.Limit, burst int, prefixes ...string)
- func (f *JSONLoggerFactory) SetWriter(w io.Writer)
- type LeveledLoggerFactory
- func (s *LeveledLoggerFactory) GetLevel(scope string) string
- func (f *LeveledLoggerFactory) NewLogger(scope string) logging.LeveledLogger
- func (s *LeveledLoggerFactory) SetLevel(levelSpec string)
- func (s *LeveledLoggerFactory) SetRateLimit(limit rate.Limit, burst int, prefixes ...string)
- func (f *LeveledLoggerFactory) SetWriter(w io.Writer)
- type LoggerFactory
- type Options
- type RateLimitedWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AutoFlushWriter ¶
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.
type JSONLoggerFactory ¶
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) 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 ¶
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 ¶
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) 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 ¶
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.