@@ -135,29 +135,32 @@ func (j *journaldWatcher) watchLoop() {
135
135
}
136
136
137
137
const (
138
- // defaultJournalLogPath is the default path of journal log.
139
- defaultJournalLogPath = "/var/log/journal"
140
-
141
138
// configSourceKey is the key of source configuration in the plugin configuration.
142
139
configSourceKey = "source"
143
140
)
144
141
145
142
// getJournal returns a journal client.
146
143
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
+ }
161
164
}
162
165
// Seek journal client based on startTime.
163
166
seekTime := startTime
0 commit comments