File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,39 @@ process:
256256 }
257257}
258258
259+ // FollowTail synchronously follows the JournalReader, writing each new journal entry to writer. The
260+ // follow will continue until a single time.Time is received on the until channel.
261+ func (r * JournalReader ) FollowTail (entries chan * JournalEntry ) error {
262+ defer close (entries )
263+
264+ // skip first entry which has already been read
265+ if _ , err := r .journal .Next (); err != nil {
266+ return err
267+ }
268+
269+ for {
270+ status := r .journal .Wait (200 * time .Millisecond )
271+ if status != SD_JOURNAL_APPEND && status != SD_JOURNAL_INVALIDATE {
272+ continue
273+ }
274+
275+ for {
276+ if c , err := r .journal .Next (); err != nil {
277+ return err
278+ } else if c == 0 {
279+ // EOF, should mean we're at the tail
280+ break
281+ }
282+
283+ if entry , err := r .journal .GetEntry (); err != nil {
284+ return err
285+ } else {
286+ entries <- entry
287+ }
288+ }
289+ }
290+ }
291+
259292// simpleMessageFormatter is the default formatter.
260293// It returns a string representing the current journal entry in a simple format which
261294// includes the entry timestamp and MESSAGE field.
You can’t perform that action at this time.
0 commit comments