Skip to content

Commit

Permalink
[release-18.0] Fix logging issue when running in Docker with the sysl…
Browse files Browse the repository at this point in the history
…og daemon disabled (#15176) (#15185)

Signed-off-by: Florent Poinsard <[email protected]>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
  • Loading branch information
vitess-bot[bot] authored Feb 8, 2024
1 parent 2a388c7 commit 5600c2b
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 @@ -52,9 +52,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 @@ -143,10 +145,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 5600c2b

Please sign in to comment.