Make log more resilient

This commit is contained in:
Daniel 2018-09-27 15:57:01 +02:00
parent 9ab95b1926
commit 45e187f883
3 changed files with 12 additions and 9 deletions

View file

@ -22,6 +22,15 @@ func log_fastcheck(level severity) bool {
func log(level severity, msg string) {
if !started.IsSet() {
// resouce intense, but keeps logs before logging started.
go func(){
time.Sleep(1 * time.Second)
log(level, msg)
}()
return
}
// check if level is enabled
if !fileLevelsActive.IsSet() && uint32(level) < atomic.LoadUint32(logLevel) {
return

View file

@ -138,10 +138,10 @@ func Start() error {
SetFileLevels(newFileLevels)
}
fmt.Println(fmt.Sprintf("%s%s ▶ BOF%s", InfoLevel.color(), time.Now().Format("060102 15:04:05.000"), endColor()))
go writer()
Info("logging: started")
return nil
return nil
}
// Shutdown writes remaining log lines and then stops the logger.

View file

@ -43,13 +43,7 @@ func writer() {
case line = <-logBuffer:
writeLine(line)
case <-time.After(10 * time.Millisecond):
writeLine(&logLine{
"===== LOGGING STOPPED =====",
WarningLevel,
time.Now(),
"",
0,
})
fmt.Println(fmt.Sprintf("%s%s ◀ EOF%s", InfoLevel.color(), time.Now().Format("060102 15:04:05.000"), endColor()))
return
}
}