summaryrefslogtreecommitdiff
path: root/internal/logger/logger.go
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2021-02-25 09:56:23 -0800
committerStan Hu <stanhu@gmail.com>2021-02-25 13:12:28 -0800
commite0d571fe334808d8549bb399d75f5120f89bbeb2 (patch)
treeddb205b0f59e51d9d886f67bf9b9f53d23f150a7 /internal/logger/logger.go
parentc0a75dae6ec448c1c82eb94b58488cdd8f6759be (diff)
downloadgitlab-shell-sh-fix-log-permission-error.tar.gz
Fix gitlab-shell panic when log file not writablesh-fix-log-permission-error
Previously when the gitlab-shell log was not writable, gitlab-shell would attempt to fall back to the syslog to log an error. However, if the syslog logger creation succeeded, gitlab-shell would panic since `err` was `nil`. Relates to https://gitlab.com/gitlab-org/gitlab-shell/-/issues/510
Diffstat (limited to 'internal/logger/logger.go')
-rw-r--r--internal/logger/logger.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/internal/logger/logger.go b/internal/logger/logger.go
index f836555..3608574 100644
--- a/internal/logger/logger.go
+++ b/internal/logger/logger.go
@@ -22,8 +22,10 @@ func Configure(cfg *config.Config) {
logFile, err := os.OpenFile(cfg.LogFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
progName, _ := os.Executable()
- syslogLogger, err := syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_USER, 0)
- syslogLogger.Print(progName + ": Unable to configure logging: " + err.Error())
+ syslogLogger, sysLogErr := syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_USER, 0)
+ if sysLogErr != nil {
+ syslogLogger.Print(progName + ": Unable to configure logging: " + err.Error())
+ }
// Discard logs since a log file was specified but couldn't be opened
log.SetOutput(ioutil.Discard)