finished tag implementation
This commit is contained in:
parent
b3b62af3a4
commit
c3076c328a
28 changed files with 396 additions and 296 deletions
47
pkg/log/scanlog.go
Normal file
47
pkg/log/scanlog.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/core"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const defaultSize = 500
|
||||
|
||||
type ScanLog struct {
|
||||
// protects logs
|
||||
sync.RWMutex
|
||||
|
||||
size int
|
||||
logs []string
|
||||
}
|
||||
|
||||
func NewScanLog(size int) *ScanLog {
|
||||
if size <= 0 {
|
||||
size = defaultSize
|
||||
}
|
||||
return &ScanLog{size: size}
|
||||
}
|
||||
|
||||
func (l *ScanLog) Printf(f string, v ...interface{}) {
|
||||
s := fmt.Sprintf(f, v...)
|
||||
Println(s)
|
||||
s = core.LogTime() + s
|
||||
l.Lock()
|
||||
logsLen := len(l.logs)
|
||||
if logsLen < l.size {
|
||||
l.logs = append(l.logs, s)
|
||||
} else if logsLen == l.size {
|
||||
l.logs = append(l.logs[1:], s)
|
||||
}
|
||||
l.Unlock()
|
||||
}
|
||||
|
||||
func (l *ScanLog) Logs() (logs string) {
|
||||
l.RLock()
|
||||
for _, v := range l.logs {
|
||||
logs += "\n" + v
|
||||
}
|
||||
l.RUnlock()
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue