Hopefully you’re already aware of the wondrous WordPress plugin, Stream, for tracking changes to your site. Stream has been through a number of iterations: v1.0 logged activity to your self-hosted WordPress site’s database, v2.0 logged activity to a cloud-hosted service, and now v3.0 logs to your self-hosted WordPress site’s database again.
Why is it a problem?
For me personally, logging to the WordPress database isn’t ideal for two main reasons:
- Keeping your audit trail inside the system you’re auditing doesn’t make sense. If your WordPress site is compromised, it would be more advantageous for activity to be logged elsewhere.
- If your WordPress site whitescreens, and you can’t get access to it, it would be useful to be able to access your Stream activity. Keeping it somewhere separate may help you troubleshoot what happened.
There are probably other reasons too, but these are the main ones.
Papertrail as a solution
I decided to create a plugin that would hook into Stream and also send logged activity elsewhere. I had a few criteria for this:
- Long-term storage
This would also have a the effect of allowing me to disable the “Keep Records Indefinitely” option on Stream, and keep all that extra data out of my WordPress database.
I looked at a number of hosted logging services. Loggly and Papertrail came out on top as my preferences. Both are built to handle high volumes of logging traffic, and handle archiving to Amazon S3 for you.
For my personal site I can live with 7 days of searchable history, so Papertrail’s plans worked better for me than Loggly’s in this case.
So I developed Stream to Papertrail.
How I set it up
On my personal site, I have installed Stream and Stream to Papertrail. I’ve also set Papertrail to archive to a bucket on Amazon S3 (which it does nightly).
The logs are JSON, so I’ve turned on the colourisation option to make tailing them in Papertrail a little easier on the eyes. Keep in mind though that this does add ANSII escape code data into your logs, which means you need to be a aware of that when searching.
Hopefully you find this useful! Especially if you already use Papertrail for logging on your web servers, you can now include WordPress activity in those logs!
If you have any other suggestions for how I could improve this setup, I’d love to hear them. Please feel free to leave a comment here, or @Japh on Twitter.