aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-08-07 20:52:31 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-20 12:26:47 +0200
commit9d4a61503c5eddad814cd3cd825a586d612f15e6 (patch)
tree330e275bf289f442bb1f2707dd96db3208dfe999 /config
parent2a83d3e9c872f38b8dd7b7a214310d87adefb25e (diff)
downloadaerc-9d4a61503c5eddad814cd3cd825a586d612f15e6.tar.gz
log: handle config reload
Prepare the logging system for a config file reload. Make sure that we never close os.Stdout but only log file descriptors. Note that if you started aerc by redirecting its output into a specific file, this cannot be changed by a config reload. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config')
-rw-r--r--config/general.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/config/general.go b/config/general.go
index e90deffe..7ea2509b 100644
--- a/config/general.go
+++ b/config/general.go
@@ -33,8 +33,11 @@ func parseGeneral(file *ini.File) error {
if err := MapToStruct(file.Section("general"), General, true); err != nil {
return err
}
+
+ useStdout := false
if !isatty.IsTerminal(os.Stdout.Fd()) {
logFile = os.Stdout
+ useStdout = true
// redirected to file, force TRACE level
General.LogLevel = log.TRACE
} else if General.LogFile != "" {
@@ -47,11 +50,17 @@ func parseGeneral(file *ini.File) error {
logFile, err = os.OpenFile(path,
os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600)
if err != nil {
- return fmt.Errorf("log-file: %w", err)
+ return err
}
}
- log.Init(logFile, General.LogLevel)
+
+ err := log.Init(logFile, useStdout, General.LogLevel)
+ if err != nil {
+ return err
+ }
+
log.Debugf("aerc.conf: [general] %#v", General)
+
return nil
}