Is there a better way to monitor a log file?

Hi all
new to julia and so still learning the basics. I have a log file that another system updates about every 1 second. It’s just a simple text file and each “row” is about 1k bytes. I just want to get the “updates” so I thought to just check every 0.5 second.

Right now I have this working BUT is there a better way?

file = open("the_log_file.log")
seekend(file)  # keep sniffing the last entry only.

while true
    sleep(0.5)
    data = read(file, String)
    !isempty(data) && print(data)
end 

Thank you

Maybe not work your looking for (since it doesn’t involve Julia) but there is tail -f the_log_file.log.

1 Like

Hey @carstenbauer

thanks for the interest. You are right, I want to keep this inside Julia so I can get a better idea about the internals. I did consider calling the tail function and it makes a lot of sense but for now I’d like to use this goal to learn more about how Julia works.

thanks for the suggestion though.

You probably want the FileWatching stdlib.

2 Likes

hi there
@oxinabox
Thanks for another great suggestion. I am trying to get a laundry list of things to try. There are many ways to get this done I’m looking for the most sensible.