Update dlog

This commit is contained in:
Frank Denis 2018-02-06 16:07:54 +01:00
parent 404c21816e
commit 6863ab66d5
4 changed files with 33 additions and 6 deletions

4
Gopkg.lock generated
View File

@ -77,10 +77,10 @@
revision = "0fb14efe8c47ae851c0034ed7a448854d3d34cf3"
[[projects]]
branch = "master"
name = "github.com/jedisct1/dlog"
packages = ["."]
revision = "2318da0182ccf19c77f0dab8a97c5eacd111cb84"
version = "0.2"
revision = "9025b39d3d9a4e268e01f536c71c6177518fc461"
[[projects]]
branch = "master"

View File

@ -15,11 +15,11 @@
"windows/registry",
"windows/svc/eventlog"
]
revision = "2c42eef0765b9837fbdab12011af7830f55f88f0"
revision = "37707fdb30a5b38865cfb95e5aab41707daec7fd"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "7dd24393da8db7d16249fa8f14426fb6418a2cefca2045da212cf4f299a5a1f0"
inputs-digest = "328c0e201a8f9b84770fc7b0efb002f50e64da384499776e57cc1edb38b26a51"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -1,3 +1,7 @@
[[constraint]]
branch = "master"
name = "github.com/hashicorp/go-syslog"
[[constraint]]
branch = "master"
name = "golang.org/x/sys"

View File

@ -22,12 +22,18 @@ type globals struct {
systemLogger *systemLogger
fileName *string
outFd *os.File
lastMessage string
lastOccurrence time.Time
occurrences uint64
}
var (
_globals = globals{
logLevel: SeverityLast,
appName: "-",
logLevel: SeverityLast,
appName: "-",
lastMessage: "",
lastOccurrence: time.Now(),
occurrences: 0,
}
)
@ -42,6 +48,11 @@ const (
SeverityLast
)
const (
FloodDelay = 5 * time.Second
FloodMinRepeats = 3
)
var SeverityName = []string{
SeverityDebug: "DEBUG",
SeverityInfo: "INFO",
@ -183,6 +194,18 @@ func logf(severity Severity, format string, args ...interface{}) {
}
_globals.Lock()
defer _globals.Unlock()
if _globals.lastMessage == message {
if time.Since(_globals.lastOccurrence) < FloodDelay {
_globals.occurrences++
if _globals.occurrences > FloodMinRepeats {
return
}
}
} else {
_globals.occurrences = 0
_globals.lastMessage = message
}
_globals.lastOccurrence = now
if *_globals.useSyslog && _globals.systemLogger == nil {
systemLogger, err := newSystemLogger(_globals.appName, _globals.syslogFacility)
if err == nil {