mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-21 15:45:01 +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"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -29,7 +30,6 @@ func Init() {
|
||||||
validateLoggerLevel()
|
validateLoggerLevel()
|
||||||
validateLoggerFormat()
|
validateLoggerFormat()
|
||||||
go errorsLoggedCleaner()
|
go errorsLoggedCleaner()
|
||||||
go logMessageWriter()
|
|
||||||
logAllFlags()
|
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)
|
logMsg = fmt.Sprintf("%s\t%s\t%s:%d\t%s\n", timestamp, levelLowercase, file, line, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
// Serialize writes to log.
|
||||||
case logMessageCh <- logMsg:
|
mu.Lock()
|
||||||
default:
|
fmt.Fprint(os.Stderr, logMsg)
|
||||||
// Writing to log can stuck if the log output isn't consumed in timely manner.
|
mu.Unlock()
|
||||||
// Handle this case via `vm_log_messages_dropped_total`
|
|
||||||
logMessagesDropped.Inc()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment vm_log_messages_total
|
// Increment vm_log_messages_total
|
||||||
location := fmt.Sprintf("%s:%d", file, line)
|
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`)
|
var mu sync.Mutex
|
||||||
|
|
||||||
func logMessageWriter() {
|
|
||||||
for msg := range logMessageCh {
|
|
||||||
fmt.Fprint(os.Stderr, msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var logMessageCh = make(chan string, 100)
|
|
||||||
|
|
||||||
func shouldSkipLog(level string) bool {
|
func shouldSkipLog(level string) bool {
|
||||||
switch *loggerLevel {
|
switch *loggerLevel {
|
||||||
|
|
Loading…
Reference in a new issue