|
@@ -24,6 +24,8 @@ import (
|
|
|
"os"
|
|
"os"
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
+ "github.com/coreos/etcd/pkg/systemd"
|
|
|
|
|
+
|
|
|
"github.com/coreos/go-systemd/journal"
|
|
"github.com/coreos/go-systemd/journal"
|
|
|
"go.uber.org/zap/zapcore"
|
|
"go.uber.org/zap/zapcore"
|
|
|
)
|
|
)
|
|
@@ -33,8 +35,8 @@ import (
|
|
|
// back to writing to the original writer.
|
|
// back to writing to the original writer.
|
|
|
// The decode overhead is only <30µs per write.
|
|
// The decode overhead is only <30µs per write.
|
|
|
// Reference: https://github.com/coreos/pkg/blob/master/capnslog/journald_formatter.go
|
|
// Reference: https://github.com/coreos/pkg/blob/master/capnslog/journald_formatter.go
|
|
|
-func NewJournaldWriter(wr io.Writer) io.Writer {
|
|
|
|
|
- return &journaldWriter{Writer: wr}
|
|
|
|
|
|
|
+func NewJournaldWriter(wr io.Writer) (io.Writer, error) {
|
|
|
|
|
+ return &journaldWriter{Writer: wr}, systemd.DialJournal()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type journaldWriter struct {
|
|
type journaldWriter struct {
|
|
@@ -82,6 +84,8 @@ func (w *journaldWriter) Write(p []byte) (int, error) {
|
|
|
"SYSLOG_IDENTIFIER": filepath.Base(os.Args[0]),
|
|
"SYSLOG_IDENTIFIER": filepath.Base(os.Args[0]),
|
|
|
})
|
|
})
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
|
|
+ // "journal" also falls back to stderr
|
|
|
|
|
+ // "fmt.Fprintln(os.Stderr, s)"
|
|
|
return w.Writer.Write(p)
|
|
return w.Writer.Write(p)
|
|
|
}
|
|
}
|
|
|
return 0, nil
|
|
return 0, nil
|