add requests/errors to stats
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user