Skip to content

Commit b9fedff

Browse files
committed
Merge pull request #138 from yifan-gu/sdjournal_path
sdjournal: Add 'Path' in config to let NewJournalReader() select journal dir.
2 parents dd4f6b8 + f94b407 commit b9fedff

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

sdjournal/read.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ type JournalReaderConfig struct {
3737
// Show only journal entries whose fields match the supplied values. If
3838
// the array is empty, entries will not be filtered.
3939
Matches []Match
40+
41+
// If not empty, the journal instance will point to a journal residing
42+
// in this directory. The supplied path may be relative or absolute.
43+
Path string
4044
}
4145

4246
// JournalReader is an io.ReadCloser which provides a simple interface for iterating through the
@@ -50,9 +54,14 @@ type JournalReader struct {
5054
func NewJournalReader(config JournalReaderConfig) (*JournalReader, error) {
5155
r := &JournalReader{}
5256

53-
var err error
5457
// Open the journal
55-
if r.journal, err = NewJournal(); err != nil {
58+
var err error
59+
if config.Path != "" {
60+
r.journal, err = NewJournalFromDir(config.Path)
61+
} else {
62+
r.journal, err = NewJournal()
63+
}
64+
if err != nil {
5665
return nil, err
5766
}
5867

0 commit comments

Comments
 (0)