Skip to content

Commit

Permalink
Fix logging issue when running in Docker with the syslog daemon disab…
Browse files Browse the repository at this point in the history
…led (#15176)

Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui authored Feb 8, 2024
1 parent d3b2593 commit 1f728ea
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion go/event/syslogger/syslogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ import (
"fmt"
"log/syslog"
"os"
"testing"

"vitess.io/vitess/go/event"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/servenv"
)

// Syslogger is the interface that events should implement if they want to be
Expand Down Expand Up @@ -145,10 +147,28 @@ func listener(ev Syslogger) {
}

func init() {
// We only want to init syslog when the app is being initialized
// Some binaries import the syslog package indirectly leading to
// the syslog.New function being called and this might fail if
// running inside Docker without the syslog daemon enabled, leading
// logging the error which will make glog think there are not --log_dir
// flag set as we have not parsed the flags yet.
// https://github.com/vitessio/vitess/issues/15120
servenv.OnInit(func() {
initSyslog()
})

// We still do the init of syslog if we are testing this package.
if testing.Testing() {
initSyslog()
}
}

func initSyslog() {
var err error
writer, err = syslog.New(syslog.LOG_INFO|syslog.LOG_USER, os.Args[0])
if err != nil {
log.Errorf("can't connect to syslog")
log.Errorf("can't connect to syslog: %v", err.Error())
writer = nil
}

Expand Down

0 comments on commit 1f728ea

Please sign in to comment.