Following your error logs for Moodle

I just wanted to share one of the commands I used on a daily basis. This works even better if you have a monitor where you can constantly view your logs.

sudo find /var/log -type f \( -name "*error*log" -not -name "ssl_error_log" \) -exec tail -f {} +|grep --line-buffered -v -E 'does not exist|new session|aborted automatically|Failed Login|Deleted Login'|cat

What does it do? Keeps a running log of your error files to let you know as soon as there is an error.

Let’s break it down.

  • sudo – some log files require you to have sudo or root privileges to read them.
  • find /var/log – find all files in the /var/log directory
  • -type f – only files
  • \( -name “*error*log” -not -name “ssl_error_log” \) – only files containing the word “error” in their name, ending in log, and not the ssl_error_log file.
  • -exec tail -f  {} + – after you’ve gotten those files, get the end of them (tail) and follow them (-f)
  • | – do this after you get the file
  • grep –line-buffered – search for a specific text in the output
  • -v – exclude specified lines
  • -E ‘does not exist|new session|aborted automatically|Failed Login|Deleted Login’ – These, are pretty specific to Moodle… I don’t really care, at this moment, about these errors. They should be looked into, but they aren’t bringing anything down.

I also have a similar command that simply emails me the message daily and logs them in a database, in case I don’t get to them. Soon to share… stay tuned!