mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Make log more resilient
This commit is contained in:
parent
9ab95b1926
commit
45e187f883
3 changed files with 12 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue