* feat(backend): try a new approach for logs formatting (http) * feat(backend): added logger module * feat(backend): added project/session info to /i endpoint * feat(backend): found a solution for correct caller information * feat(backend): finished logs for http handlers * feat(backend): finished logs for mobile http handlers * feat(backend): finished ender * feat(backend): finished assets * feat(backend): finished heuristics * feat(backend): finished image-storage * feat(backend): finished sink * feat(backend): finished storage * feat(backend): formatted logs in all services * feat(backend): finished foss part * feat(backend): added missed foss part * feat(backend): fixed panic in memory manager and sink service * feat(backend): connectors
50 lines
791 B
Go
50 lines
791 B
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
type logCounter struct {
|
|
mu sync.Mutex
|
|
counter int
|
|
timestamp time.Time
|
|
lastTS time.Time
|
|
lastSessID uint64
|
|
}
|
|
|
|
func NewLogCounter() *logCounter {
|
|
nlc := &logCounter{}
|
|
nlc.init()
|
|
return nlc
|
|
}
|
|
|
|
func (c *logCounter) init() {
|
|
c.mu.Lock()
|
|
c.counter = 0
|
|
c.timestamp = time.Now()
|
|
c.mu.Unlock()
|
|
}
|
|
|
|
func (c *logCounter) Update(sessID uint64, ts time.Time) {
|
|
c.mu.Lock()
|
|
c.counter++
|
|
c.lastTS = ts
|
|
c.lastSessID = sessID
|
|
c.mu.Unlock()
|
|
}
|
|
|
|
func (c *logCounter) Log() string {
|
|
c.mu.Lock()
|
|
res := fmt.Sprintf("count: %d, dur: %ds, msgTS: %s, sessID: %d, part: %d",
|
|
c.counter,
|
|
int(time.Now().Sub(c.timestamp).Seconds()),
|
|
c.lastTS.String(),
|
|
c.lastSessID,
|
|
c.lastSessID%16,
|
|
)
|
|
c.mu.Unlock()
|
|
c.init()
|
|
return res
|
|
}
|