Skip to content
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 line position to Line #49

Open
mkmik opened this issue Jun 3, 2015 · 1 comment
Open

Add line position to Line #49

mkmik opened this issue Jun 3, 2015 · 1 comment
Labels

Comments

@mkmik
Copy link

mkmik commented Jun 3, 2015

Hi,

Nice library!

I'd like to be able to tell when the file is reopened. However having to deal with an event (channel, error code, ...) in case of reopen feels like a kludge. What about simply adding a byte position of the start of each line in the Line structure. There is already the timestamp. This way users can detect when the file was reopened because the position is no longer monotonically increasing.

What do you think?

@srid
Copy link
Contributor

srid commented Jul 1, 2015

If the original intent is to detect a reopen event, then the issue title should say so, should it not? Adding line position is only a workaround to achieve this goal (and the user code would still have keep track of the monotonically increasing pattern). Taking a step back and thinking about this problem ...

Go unfortunately has no algebraic types - otherwise you could just make a channel of "either" Line or Err or Event and be done with it.

So, one solution is to add a new field called Event:

type Line struct {
    Text string
    Time time.Time
    Err  error // Error from tail
    Event  Event // eg: reopen event
}

Just like Err, Event will be nil most of the time. If we had algebraic types (or union types) support, these fields need be put in the Line struct. The user code will now have to do two checks — if line.Err != nil; if line.Event != nil — before getting to process the actual lines. However this seems like bad API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants