add requests/errors to stats

This commit is contained in:
Asim Aslam
2019-12-18 18:36:42 +00:00
parent d4bec24eb7
commit d52a111735
8 changed files with 197 additions and 59 deletions

View File

@@ -15,6 +15,8 @@ import (
// Should stream from OS
type osLog struct {
once sync.Once
sync.RWMutex
buffer *ring.Buffer
subs map[string]*osStream
@@ -118,6 +120,10 @@ func (o *osLog) run() {
// Read reads log entries from the logger
func (o *osLog) Read(...ReadOption) ([]Record, error) {
o.once.Do(func() {
go o.run()
})
var records []Record
// read the last 100 records
@@ -130,6 +136,10 @@ func (o *osLog) Read(...ReadOption) ([]Record, error) {
// Write writes records to log
func (o *osLog) Write(r Record) error {
o.once.Do(func() {
go o.run()
})
b, _ := json.Marshal(r)
_, err := os.Stderr.Write(append(b, byte('\n')))
return err
@@ -137,6 +147,10 @@ func (o *osLog) Write(r Record) error {
// Stream log records
func (o *osLog) Stream() (Stream, error) {
o.once.Do(func() {
go o.run()
})
o.Lock()
defer o.Unlock()
@@ -172,7 +186,5 @@ func NewLog(opts ...Option) Log {
subs: make(map[string]*osStream),
}
go l.run()
return l
}