mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
Revert "lib/logger: prevent from blocking when log output isn't consumed in timely manner"
This reverts commit e3c462f08a
.
Reason to revert: this leaves incomplete logs on app shutdown.
This commit is contained in:
parent
5b75984aa9
commit
31d04fb5df
1 changed files with 6 additions and 17 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
|
@ -29,7 +30,6 @@ func Init() {
|
|||
validateLoggerLevel()
|
||||
validateLoggerFormat()
|
||||
go errorsLoggedCleaner()
|
||||
go logMessageWriter()
|
||||
logAllFlags()
|
||||
}
|
||||
|
||||
|
@ -137,13 +137,10 @@ func logMessage(level, msg string, skipframes int) {
|
|||
logMsg = fmt.Sprintf("%s\t%s\t%s:%d\t%s\n", timestamp, levelLowercase, file, line, msg)
|
||||
}
|
||||
|
||||
select {
|
||||
case logMessageCh <- logMsg:
|
||||
default:
|
||||
// Writing to log can stuck if the log output isn't consumed in timely manner.
|
||||
// Handle this case via `vm_log_messages_dropped_total`
|
||||
logMessagesDropped.Inc()
|
||||
}
|
||||
// Serialize writes to log.
|
||||
mu.Lock()
|
||||
fmt.Fprint(os.Stderr, logMsg)
|
||||
mu.Unlock()
|
||||
|
||||
// Increment vm_log_messages_total
|
||||
location := fmt.Sprintf("%s:%d", file, line)
|
||||
|
@ -158,15 +155,7 @@ func logMessage(level, msg string, skipframes int) {
|
|||
}
|
||||
}
|
||||
|
||||
var logMessagesDropped = metrics.NewCounter(`vm_log_messages_dropped_total`)
|
||||
|
||||
func logMessageWriter() {
|
||||
for msg := range logMessageCh {
|
||||
fmt.Fprint(os.Stderr, msg)
|
||||
}
|
||||
}
|
||||
|
||||
var logMessageCh = make(chan string, 100)
|
||||
var mu sync.Mutex
|
||||
|
||||
func shouldSkipLog(level string) bool {
|
||||
switch *loggerLevel {
|
||||
|
|
Loading…
Reference in a new issue