mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-01 19:18:28 -04:00
core: fix log file deadlock
port 1.5
This commit is contained in:
@@ -124,7 +124,9 @@ func GetLogger() *Logger {
|
|||||||
logger = &Logger{base}
|
logger = &Logger{base}
|
||||||
|
|
||||||
if path := os.Getenv("DMS_LOG_FILE"); path != "" {
|
if path := os.Getenv("DMS_LOG_FILE"); path != "" {
|
||||||
_ = SetLogFile(path)
|
logMu.Lock()
|
||||||
|
_ = setLogFile(logger, path)
|
||||||
|
logMu.Unlock()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return logger
|
return logger
|
||||||
@@ -145,15 +147,18 @@ func SetLevel(level string) {
|
|||||||
// profile when stderr is a TTY and route the file through ansiStripWriter so
|
// profile when stderr is a TTY and route the file through ansiStripWriter so
|
||||||
// the file stays plain while stderr keeps its colors.
|
// the file stays plain while stderr keeps its colors.
|
||||||
func SetLogFile(path string) error {
|
func SetLogFile(path string) error {
|
||||||
|
l := GetLogger()
|
||||||
logMu.Lock()
|
logMu.Lock()
|
||||||
defer logMu.Unlock()
|
defer logMu.Unlock()
|
||||||
|
return setLogFile(l, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setLogFile(l *Logger, path string) error {
|
||||||
if logFile != nil {
|
if logFile != nil {
|
||||||
logFile.Close()
|
logFile.Close()
|
||||||
logFile = nil
|
logFile = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
l := GetLogger()
|
|
||||||
if path == "" {
|
if path == "" {
|
||||||
l.SetOutput(logStderr)
|
l.SetOutput(logStderr)
|
||||||
applyColorProfile(l, logStderr)
|
applyColorProfile(l, logStderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user