Mike Putnam

All posts ...
Connect via: Github Google+ LinkedIn Twitter
Get involved: Appleton Makerspace Wisconsin Linux Users

Tail foreverjs logs

Forever is "a simple CLI tool for ensuring that a given script runs continuously (i.e. forever)."

Forever includes a command ( $ forever logs 0 ) to show you the last 100 lines of stdout/stderr for the processes it is watching. Often 100 lines is enough to see what you were hoping to see.

But sometimes 100 lines is not enough and instead you would like to see a live tail of the forever watched process. Linux/Unix based operating system tools to the rescue!

Running $ forever logs (assuming you are only watching a single process) will emit 3 lines of output. The third line contains the full path to the log file. Knowing this we can construct a simple pipeline:

$ forever logs | awk 'NR==3' | awk '{print $4}' | xargs tail -f

Above, forever emits its output => awk grabs the 3rd line using it's "number of record/NR" syntax => another awk prints the 4th space delimited string from that line (the path) => and finally xargs takes that and runs tail -f(ollow)!

Familiarity with these *nix tools is infinitely reuseable as plain text is the most common protocol and these tools are purpose built for working with text.

comments powered by Disqus