Skip to content

Commit

Permalink
Merge pull request #138 from yifan-gu/sdjournal_path
Browse files Browse the repository at this point in the history
sdjournal: Add 'Path' in config to let NewJournalReader() select journal dir.
  • Loading branch information
jonboulle committed Jan 13, 2016
2 parents dd4f6b8 + f94b407 commit b9fedff
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sdjournal/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type JournalReaderConfig struct {
// Show only journal entries whose fields match the supplied values. If
// the array is empty, entries will not be filtered.
Matches []Match

// If not empty, the journal instance will point to a journal residing
// in this directory. The supplied path may be relative or absolute.
Path string
}

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

var err error
// Open the journal
if r.journal, err = NewJournal(); err != nil {
var err error
if config.Path != "" {
r.journal, err = NewJournalFromDir(config.Path)
} else {
r.journal, err = NewJournal()
}
if err != nil {
return nil, err
}

Expand Down

0 comments on commit b9fedff

Please sign in to comment.