Documentation ¶
Index ¶
- Variables
- func Init(stats Stats, reporting Reporting) error
- func InitDefault() error
- type Bucket
- type Context
- type DefaultStatsAndReporting
- func (ds *DefaultStatsAndReporting) Count(event string) uint64
- func (ds *DefaultStatsAndReporting) Log(event string)
- func (ds *DefaultStatsAndReporting) LogBytes(event string, bytes uint64)
- func (ds *DefaultStatsAndReporting) LogInterval(event string, interval time.Duration)
- func (ds *DefaultStatsAndReporting) Logger() *zap.SugaredLogger
- func (ds *DefaultStatsAndReporting) Name() string
- func (ds *DefaultStatsAndReporting) Snapshot() *Snapshot
- func (ds *DefaultStatsAndReporting) WithContext(name string) Stats
- type Reporting
- type Snapshot
- func (snap *Snapshot) Bytes(event string) uint64
- func (snap *Snapshot) Count(event string) uint64
- func (snap *Snapshot) Diff(other *Snapshot) *Snapshot
- func (snap *Snapshot) Filter(prefix string) *Snapshot
- func (snap *Snapshot) Interval(event string) time.Duration
- func (snap *Snapshot) Keys() []string
- func (snap *Snapshot) MarshalJSON() ([]byte, error)
- func (snap *Snapshot) Write(log *zap.SugaredLogger)
- type Stats
Constants ¶
This section is empty.
Variables ¶
var ( GLOBAL_STATS Stats = nil GLOBAL_REPORTING Reporting = nil )
Global stats and reporting instances.
Functions ¶
func InitDefault ¶
func InitDefault() error
InitDefault initializes the global stats and reporting instances with a DefaultStatsAndReporting instance.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a Stats implementation that adds a prefix to all events.
func (*Context) LogInterval ¶
Log records an event.
func (*Context) Logger ¶
func (ctx *Context) Logger() *zap.SugaredLogger
Logger returns a logger that adds a prefix to all events.
func (*Context) WithContext ¶
WithContext returns a new Stats instance that adds a prefix to all events.
type DefaultStatsAndReporting ¶
type DefaultStatsAndReporting struct {
// contains filtered or unexported fields
}
DefaultStatsAndReporting is a Stats and Reporting implementation that records events in memory.
func NewDefaultStatsAndReporting ¶
func NewDefaultStatsAndReporting() *DefaultStatsAndReporting
NewDefaultStatsAndReporting returns a new DefaultStatsAndReporting instance.
func (*DefaultStatsAndReporting) Count ¶
func (ds *DefaultStatsAndReporting) Count(event string) uint64
Count returns the number of times the given event has been recorded.
func (*DefaultStatsAndReporting) Log ¶
func (ds *DefaultStatsAndReporting) Log(event string)
Log records an event.
func (*DefaultStatsAndReporting) LogBytes ¶
func (ds *DefaultStatsAndReporting) LogBytes(event string, bytes uint64)
func (*DefaultStatsAndReporting) LogInterval ¶
func (ds *DefaultStatsAndReporting) LogInterval(event string, interval time.Duration)
func (*DefaultStatsAndReporting) Logger ¶
func (ds *DefaultStatsAndReporting) Logger() *zap.SugaredLogger
Logger returns a logger that adds a prefix to all events.
func (*DefaultStatsAndReporting) Name ¶
func (ds *DefaultStatsAndReporting) Name() string
Name returns the name of this DefaultStatsAndReporting instance.
func (*DefaultStatsAndReporting) Snapshot ¶
func (ds *DefaultStatsAndReporting) Snapshot() *Snapshot
Snapshot returns a snapshot of the current DefaultStatsAndReporting instance.
func (*DefaultStatsAndReporting) WithContext ¶
func (ds *DefaultStatsAndReporting) WithContext(name string) Stats
WithContext returns a new Context instance that adds a prefix to all events.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is a snapshot of a Stats instance.
func (*Snapshot) Diff ¶
Diff returns a new Snapshot that contains the difference between this Snapshot and the given Snapshot.
func (*Snapshot) Filter ¶
Filter returns a new Snapshot that contains only the events that match the given prefix.
func (*Snapshot) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Snapshot) Write ¶
func (snap *Snapshot) Write(log *zap.SugaredLogger)
Write writes the snapshot to the given logger.
type Stats ¶
type Stats interface { // Log records an event. Log(string) // LogInterval records an interval in nanoseconds. LogInterval(string, time.Duration) // LogBytes records an amount in bytes. LogBytes(string, uint64) // WithContext returns a new Stats instance that adds a prefix to all events. WithContext(string) Stats // Logger returns a logger that adds a prefix to all events. Logger() *zap.SugaredLogger // Name returns the name of this Stats instance. Name() string }
Stats is an interface for recording events.