Documentation ¶
Index ¶
Constants ¶
const ( DefaultRateLimit = rate.Limit(.25) DefaultBurstSize = 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LeveledLoggerFactory ¶ added in v0.16.1
type LeveledLoggerFactory struct { Writer io.Writer DefaultLogLevel logging.LogLevel ScopeLevels map[string]logging.LogLevel Loggers map[string]*RateLimitedLogger }
LeveledLoggerFactory defines levels by scopes and creates new LeveledLoggers that can dynamically change their own loglevels.
func NewLoggerFactory ¶
func NewLoggerFactory(levelSpec string) *LeveledLoggerFactory
NewLoggerFactory sets up a scoped logger for STUNner.
func (*LeveledLoggerFactory) GetLevel ¶ added in v0.16.1
func (f *LeveledLoggerFactory) GetLevel(scope string) string
GetLevel gets the loglevel 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 (if it exists) for the given scope or creates a new one.
func (*LeveledLoggerFactory) SetLevel ¶ added in v0.16.1
func (f *LeveledLoggerFactory) SetLevel(levelSpec string)
SetLevel sets the loglevel.
func (*LeveledLoggerFactory) WithRateLimiter ¶ added in v0.16.1
func (f *LeveledLoggerFactory) WithRateLimiter(limit rate.Limit, burst int) *RateLimitedLoggerFactory
WithRateLimiter decorates a logger factory with a rate-limiter. All loggers emitted by the factory will be automatically rate-limited.
type LoggerFactory ¶
type LoggerFactory interface { logging.LoggerFactory // SetLevel sets the global loglevel. SetLevel(levelSpec string) // GetLevel gets the loglevel for the given scope. GetLevel(scope string) string }
LoggerFactory is the basic pion LoggerFactory interface extended with functions for setting and querying the loglevel per scope.
type RateLimitedLogger ¶ added in v0.16.1
type RateLimitedLogger struct { *logging.DefaultLeveledLogger *RateLimitedWriter }
RateLimitedLogger is a rate-limiter logger for a specific scope.
type RateLimitedLoggerFactory ¶ added in v0.16.1
type RateLimitedLoggerFactory struct { *LeveledLoggerFactory Limit rate.Limit Burst int }
RateLimitedLoggerFactory is a logger factory that can emit rate-limited loggers. Note that all loglevels are rate-limited via single token bucket. Rate-limiting only applies at high loglevels (ERROR, WARN and INFO), a logger set to alower loglevel (DEBUG and TRACE) is never rate-limited to ease debugging.
func (*RateLimitedLoggerFactory) NewLogger ¶ added in v0.16.1
func (f *RateLimitedLoggerFactory) NewLogger(scope string) logging.LeveledLogger
NewLogger either returns the existing LeveledLogger (if it exists) for the given scope or creates a new one.
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 then the number of events suppressed between logged events is appended to the output.
type RateLimiter ¶ added in v0.16.1
RateLimiter is a token bucket that can be disabled.
func NewRateLimiter ¶ added in v0.16.1
func NewRateLimiter(r rate.Limit, b int) *RateLimiter
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()