2

I'm currently developing with Wordpress and monitoring its debug.log file which updates on every page re-load. If there's an error, it will add those lines to the debug.log on refresh. The three basic possibilities are it outputs 0 lines(no errors), 1 line(1 error), or multiple lines(multiple errors).

Currently, I have tried tail -f and/or less +F as pagers to watch for new errors upon page re-load. My problem is that I want a way to make the output more readable. At present, each of these commands just adds additional log lines to the existing list. There isn't really differentiation between lines besides the time stamp on each.

I would love a way to be able to clearly and quickly see which lines(if any) were the most recently generated - i.e. from the latest page refresh. I've looked into appending new lines/line breaks between each output, or a way to highlight the most recent line(s), etc. but don't seem to be turning up many results.

I'm open to using other commands, bash scripts, etc. I just need a way to clearly display which are the new lines in a particular log file(per page refresh). All help is appreciated!

6
  • when doing PHP dev stuff I watch the log and grep it for my IP address... is the client IP in teh debug.log ? If so, tail -f /path/to/debug.log | grep 10.22.33.44 will isolate what is shown in the logs to just YOUR traffic for testing purposes
    – ivanivan
    Commented Oct 1, 2017 at 2:39
  • @ivanivan It's local development right now so it's only my own traffic anyway. Even if it wasn't this still wouldn't get at the heart of the problem: Differentiating between error logs from last times I reloaded and error logs from the current reload. This is more about log readability than anything, and when all logs from all refreshes are lumped together, it's hard to tell which ones I need to be looking at to help with my development.
    – baelx
    Commented Oct 1, 2017 at 2:46
  • 1
    Ah. In that case, in the term window that is watching the logs with tail -f, hit the enter key a few times. you'll have each clicks worth of log entries separated by blank lines.
    – ivanivan
    Commented Oct 1, 2017 at 3:08
  • @ivanivan That's the ghetto hack I use myself, but requires human intervention.
    – user59328
    Commented Oct 1, 2017 at 3:19
  • @ivanivan Thanks for that suggestion. Ultimately, the ideal solution to my problem would be to have this automated. Do you know of any way to do that?
    – baelx
    Commented Oct 1, 2017 at 3:21

1 Answer 1

1

This is an extreme ghetto hack and I am a bad person for publishing it:

perl -le 'for(;;){print;sleep(3);}' & tail -s 10 -n 0 -f filename.txt

How it works:

  • The background perl process prints a newline to the screen every 3 seconds
  • The tail command displays new lines from filename.txt as they become available.

When you're done, be sure to kill the background perl process or it will continue printing newlines to the screen forever.

6
  • After the first refresh, your suggested command is great since it starts with none of the previous lines/outputs. However, after a few refreshes, the same problem of all log statements being lumped together emerges. Are you suggesting I run this command every time I refresh? - maybe automated with a bash script or some other tool? Any other tips you could provide would be great!
    – baelx
    Commented Oct 1, 2017 at 2:39
  • Do you just want a newline between each log message, or do you want to group a bunch of log messages together, and then have a newline. If the latter, how many log messages do you want grouped together at one time?
    – user59328
    Commented Oct 1, 2017 at 3:01
  • @fixer1234 I've been told previously that too many of my comments should actually be answers, so I pledged to start posting more answers. Should this have been a comment, then? I was expecting some back and forth, since I honestly wasn't sure if it was something this simple.
    – user59328
    Commented Oct 1, 2017 at 3:11
  • @barrycarter I've now made some edits to my original question that hopefully make it more clear. In summary, sometimes a page refresh gives 0 lines to the log files, sometimes it gives multiple. I can't control how many it gives after a given refresh but I still want a way to clearly define which have appeared after the most recent refresh and which are from earlier refreshes.
    – baelx
    Commented Oct 1, 2017 at 3:15
  • OK, edited answer.
    – user59328
    Commented Oct 1, 2017 at 3:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .