mirror of
https://github.com/safing/portbase
synced 2025-09-05 04:00:14 +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) {
|
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
|
// check if level is enabled
|
||||||
if !fileLevelsActive.IsSet() && uint32(level) < atomic.LoadUint32(logLevel) {
|
if !fileLevelsActive.IsSet() && uint32(level) < atomic.LoadUint32(logLevel) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -138,10 +138,10 @@ func Start() error {
|
||||||
SetFileLevels(newFileLevels)
|
SetFileLevels(newFileLevels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(fmt.Sprintf("%s%s ▶ BOF%s", InfoLevel.color(), time.Now().Format("060102 15:04:05.000"), endColor()))
|
||||||
go writer()
|
go writer()
|
||||||
Info("logging: started")
|
|
||||||
return nil
|
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown writes remaining log lines and then stops the logger.
|
// Shutdown writes remaining log lines and then stops the logger.
|
||||||
|
|
|
@ -43,13 +43,7 @@ func writer() {
|
||||||
case line = <-logBuffer:
|
case line = <-logBuffer:
|
||||||
writeLine(line)
|
writeLine(line)
|
||||||
case <-time.After(10 * time.Millisecond):
|
case <-time.After(10 * time.Millisecond):
|
||||||
writeLine(&logLine{
|
fmt.Println(fmt.Sprintf("%s%s ◀ EOF%s", InfoLevel.color(), time.Now().Format("060102 15:04:05.000"), endColor()))
|
||||||
"===== LOGGING STOPPED =====",
|
|
||||||
WarningLevel,
|
|
||||||
time.Now(),
|
|
||||||
"",
|
|
||||||
0,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue