forked from HouzuoGuo/tiedot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tdlog.go
54 lines (45 loc) · 1.03 KB
/
tdlog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package tdlog
import (
"fmt"
"log"
"sync"
)
// Controls whether INFO log messages are generated
var VerboseLog = false
// LVL 6
func Infof(template string, params ...interface{}) {
if VerboseLog {
log.Printf(template, params...)
}
}
func Info(params ...interface{}) {
if VerboseLog {
log.Print(params...)
}
}
// LVL 5
func Noticef(template string, params ...interface{}) {
log.Printf(template, params...)
}
func Notice(params ...interface{}) {
log.Print(params...)
}
var critHistory = make(map[string]struct{})
var critLock = new(sync.Mutex)
// LVL 2 - will not repeat a message twice over the past 100 distinct crit messages
func CritNoRepeat(template string, params ...interface{}) {
msg := fmt.Sprintf(template, params...)
critLock.Lock()
if _, exists := critHistory[msg]; !exists {
log.Print(msg)
critHistory[msg] = struct{}{}
}
if len(critHistory) > 100 {
critHistory = make(map[string]struct{})
}
critLock.Unlock()
}
// LVL 1
func Panicf(template string, params ...interface{}) {
log.Panicf(template, params...)
}