Giter VIP home page Giter VIP logo

Comments (7)

EbonJaeger avatar EbonJaeger commented on July 18, 2024 5

Figured this out by myself. Just had to specify a SeekInfo in the tail config object:

tail, err := tail.TailFile("testFile.txt", tail.Config{
    Location: &tail.SeekInfo{
        Whence: io.SeekEnd,
    },
    // Rest of config
})

from tail.

markhc avatar markhc commented on July 18, 2024 1

Thank you for responding, I have tried the same, but every time I save the file with a new line, I receive all lines from start. Instead, I want only new lines

Just gonna report my experience here because I thought I was facing the same issue as you, and it turns out that's not the case.

The library works as expected, and does not resend every line from the start if you append new lines correctly. By this I mean that you actually append new lines. What some editors do is that, when you write a new line to the end of a file and save it, the editor then opens the file in write mode and rewrites all contents to it, instead of just appending to the end. This makes tail see the file changed as a whole and so it resends all lines from the start.

If you actually use an append mode to write to the file, you will see it behave exactly as you want it to. One way to test this is to append with echo, like so echo "line content" >> /path/to/file (notice the use of >> there, not >)

from tail.

nxadm avatar nxadm commented on July 18, 2024

Than you for the digging (and excuses for my late reaction). Do you see a place where we could inprove the documentation? I am trying to cleanup and test the noTomb branch where the API and doc should be improved (https://github.com/nxadm/tail/tree/noTomb).

from tail.

EbonJaeger avatar EbonJaeger commented on July 18, 2024

No worries! Looking further into it, this is a gripe I have with Go's io package, where the Seek function lives. They use the word 'whence,' which is absolutely meaningless, but it is well-commented. So, short of having a Github wiki page or something, I'm not really sure there's actually anything you can do here. :/

from tail.

Rushi-Kumar avatar Rushi-Kumar commented on July 18, 2024

Hi Team,

This library by default returns every line again from the start if follow is enabled. how to receive only new lines? I am trying to understand but could not figure it out. Can you help me

from tail.

EbonJaeger avatar EbonJaeger commented on July 18, 2024

When I used this, I seeked to the end:

w.tail, tailErr = tail.TailFile(path, tail.Config{
    Location: &tail.SeekInfo{
        Whence: io.SeekEnd,
    },
    ReOpen: true,
    Follow: true,
})

I don't know how valid this is still, since it's been years.

from tail.

Rushi-Kumar avatar Rushi-Kumar commented on July 18, 2024

Thank you for responding,
I have tried the same, but every time I save the file with a new line, I receive all lines from start. Instead, I want only new lines

from tail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.