Skip to content

Commit 2a07254

Browse files
authored
Merge pull request #253 from finn-no/master
Empty LogPath will use journald's default path.
2 parents 6aa308d + 09c498a commit 2a07254

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

pkg/systemlogmonitor/logwatchers/journald/log_watcher.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,29 +135,32 @@ func (j *journaldWatcher) watchLoop() {
135135
}
136136

137137
const (
138-
// defaultJournalLogPath is the default path of journal log.
139-
defaultJournalLogPath = "/var/log/journal"
140-
141138
// configSourceKey is the key of source configuration in the plugin configuration.
142139
configSourceKey = "source"
143140
)
144141

145142
// getJournal returns a journal client.
146143
func getJournal(cfg types.WatcherConfig, startTime time.Time) (*sdjournal.Journal, error) {
147-
// Get journal log path.
148-
path := defaultJournalLogPath
149-
if cfg.LogPath != "" {
150-
path = cfg.LogPath
151-
}
152-
// If the path doesn't present, NewJournalFromDir will create it instead of
153-
// returning error. So check the path existence ourselves.
154-
if _, err := os.Stat(path); err != nil {
155-
return nil, fmt.Errorf("failed to stat the log path %q: %v", path, err)
156-
}
157-
// Get journal client from the log path.
158-
journal, err := sdjournal.NewJournalFromDir(path)
159-
if err != nil {
160-
return nil, fmt.Errorf("failed to create journal client from path %q: %v", path, err)
144+
var journal *sdjournal.Journal
145+
var err error
146+
if cfg.LogPath == "" {
147+
journal, err = sdjournal.NewJournal()
148+
if err != nil {
149+
return nil, fmt.Errorf("failed to create journal client from default log path: %v", err)
150+
}
151+
glog.Info("unspecified log path so using systemd default")
152+
} else {
153+
// If the path doesn't exist, NewJournalFromDir will
154+
// create it instead of returning error. So check the
155+
// path existence ourselves.
156+
if _, err = os.Stat(cfg.LogPath); err != nil {
157+
return nil, fmt.Errorf("failed to stat the log path %q: %v", cfg.LogPath, err)
158+
}
159+
// Get journal client from the log path.
160+
journal, err = sdjournal.NewJournalFromDir(cfg.LogPath)
161+
if err != nil {
162+
return nil, fmt.Errorf("failed to create journal client from path %q: %v", cfg.LogPath, err)
163+
}
161164
}
162165
// Seek journal client based on startTime.
163166
seekTime := startTime

0 commit comments

Comments
 (0)