wp-crontrol
wp-crontrol copied to clipboard
Logging for cron events
WP Crontrol should log all cron events for debugging purposes and expose the log somewhere.
This can be achieved by iterating distinct cron hooks in the cron array and adding an action which logs the event. Data to log includes:
- [x] Hook name
- [x] Timestamp
- [x] Parameters
- [x] Callbacks registered at the time the event ran
- [ ] ~~Whether it was run manually (via
Run Now) or via the regular scheduling~~ - [x] Time taken to run (via an early action and a late action with timing)
- [ ] ~~Did the event miss its scheduled time? By how much?~~
- [x] Catch fatals? Probably needs PHP 7. Re-throw them.
- [ ] PHP errors
- [x] Queries performed
- [x] HTTP API calls performed
- [x] Memory used
Plus:
- [ ] Ability to call
do_action( 'crontrol_something' )to log extra data in the event log - [ ] Ability to throw an exception to cause an event to "fail", similar to Action Scheduler
- [ ] Limit on the number of logs stored. Either a number or a time frame
- [x] Should be optional, ie. can be turned off
- [x] Ability to disable event logging by hook name, maybe a filter or maybe a UI control
- [x] Cron events by default logged in a post type, post meta, terms
- [ ] Storage should be abstracted so it can be stored elsewhere, eg Stream, Simple History, custom table, system logger
Stretch Goals:
- [ ] Extended support for Action Scheduler, list which jobs were triggered
~~This is in progress in the develop branch. Lots still to do.~~
Edit: This was pulled out. Needs adding back into the develop branch.
~~This is now available in 2.0.0-beta1. I might push the remaining features to 2.1, we'll see.~~
@johnbillion These are listed as built into the 2.0.0-beta, but that got scrubbed to 1.8.0 which has been out for some time. I do not see logging in the current versions. Did this get left out and closed on accident?
@danieliser Good point, this got reverted because it needs more work for it to be mature and stable. I didn't want to release a part-baked feature. I'll reopen this issue with more details.
In the meantime you can use the develop branch at this specific commit to get the latest version of the feature before I pulled it out: https://github.com/johnbillion/wp-crontrol/commit/3472d67560caf9bfff4477f0faee12a2a7585e76
Notably, the UX for selecting which hooks are logged needs more work, and there is no mechanism for limiting the number of events that are logged. You'll need to manually clear the logs periodically otherwise your database can balloon.
Nice, look forward to seeing it finished.
Will say we found 2 plugins that do logging, this one doesn't have a great UI/UX, but seems to function solidly: https://wordpress.org/plugins/cron-logger/
Ooh, would love to see this in Crontrol soon. Was using Cron Logger but it's clunky and not great to use.
Some long running jobs hold up the Cron for longer, so as long as "active" sessions/logs of the Cron remain visible. In Cron Logger they just drop off the page in the history even though it's still running.
I would love to see this feature too!
Me too