-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new follow method #386
base: main
Are you sure you want to change the base?
Changes from 3 commits
d644ef3
92cdb09
9ceb5b8
325976a
1d77cbd
7c68517
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,6 +256,48 @@ process: | |
} | ||
} | ||
|
||
// SkipN skips the next n entries and returns the number of skipped entries and an eventual error. | ||
func (r *JournalReader) SkipN(n int) (int, error) { | ||
var i int | ||
for i := 1; i <= n; i++ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why doesn't this start at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't notice until you mentioned it, but it really looks kind of messy! Thanks. |
||
c, err := r.journal.Next() | ||
if err != nil { | ||
return i, err | ||
} else if c == 0 { | ||
return i, nil | ||
} | ||
} | ||
return i, nil | ||
} | ||
|
||
// FollowTail synchronously follows the JournalReader, writing each new journal entry to entries. | ||
// It will start from the next unread entry. | ||
func (r *JournalReader) FollowTail(entries chan *JournalEntry) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not overly positive with this proposed signature, as it lacks at least a |
||
defer close(entries) | ||
|
||
for { | ||
status := r.journal.Wait(200 * time.Millisecond) | ||
if status != SD_JOURNAL_APPEND && status != SD_JOURNAL_INVALIDATE { | ||
continue | ||
} | ||
|
||
for { | ||
if c, err := r.journal.Next(); err != nil { | ||
return err | ||
} else if c == 0 { | ||
// EOF, should mean we're at the tail | ||
break | ||
} | ||
|
||
if entry, err := r.journal.GetEntry(); err != nil { | ||
return err | ||
} else { | ||
entries <- entry | ||
} | ||
} | ||
} | ||
} | ||
|
||
// simpleMessageFormatter is the default formatter. | ||
// It returns a string representing the current journal entry in a simple format which | ||
// includes the entry timestamp and MESSAGE field. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may be useful here to check that
n >= 0
.