Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 1, 2025

Plan to add cron arguments into logging as debug output:

  • Understand the current code structure and event object
  • Add WP_CLI::debug() call to log event arguments after successful execution
  • Format arguments appropriately (handle empty arrays, serialize complex data)
  • Add test case to verify debug output with arguments
  • Run code review - no issues found
  • Run security check - no vulnerabilities found
  • Fix PHPCS error (use single quotes)
  • Fix test assertion to match actual debug output format
  • Fix test to check STDERR for debug output

Summary

This PR adds debug output to show cron event arguments when executing cron events with the wp cron event run command. This addresses the feature request to include argument information in logging, particularly useful for events like publish_future_post where seeing the post ID would be helpful for debugging.

Changes Made

  1. Modified src/Cron_Event_Command.php:

    • Added WP_CLI::debug() call after the execution log message
    • Debug output only appears when --debug=cron flag is used
    • Arguments are displayed as JSON using wp_json_encode() for readability
    • Only displays when event has non-empty arguments
    • Fixed PHPCS error by using single quotes instead of double quotes
  2. Added test in features/cron-event.feature:

    • Tests execution with arguments and verifies debug output appears in STDERR
    • Tests execution without arguments and verifies no debug output appears
    • Uses "I try" to properly test STDERR output
    • Ensures backward compatibility

Example Usage

# Schedule an event with arguments
wp cron event schedule my_event now --0=123 --1=my-value

# Run with debug output enabled
wp cron event run my_event --due-now --debug=cron

# Output will include:
# Executed the cron event 'my_event' in 0.001s. (STDOUT)
# Debug: Arguments: ["123","my-value"] (STDERR)

The implementation is minimal, backward compatible, and follows WP-CLI best practices for debug output.

Original prompt

This section details on the original issue you should resolve

<issue_title>Feature request: Add cron arguments into logging</issue_title>
<issue_description>Would be great if the Executed the cron event 'x' message included a dump of the arguments passed in. Perhaps as part of a debug group so can be enabled/disabled via the --debug flag?

i.e. this line
https://github.com/wp-cli/cron-command/blob/master/src/Cron_Event_Command.php#L262

Personal reasoning is it'd be good to see the post ID for any publish_future_post events, but I'm sure it'd come in handy for others wanting to debug.</issue_description>

Comments on the Issue (you are @copilot in this section)

@schlessera Yes, sounds like a good change, using debug output for backwards compatibility.

Are you interested in providing a PR for this?</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add cron arguments to logging with debug option Add debug output for cron event arguments Nov 1, 2025
Copilot AI requested a review from swissspidy November 1, 2025 20:12
@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@codecov
Copy link

codecov bot commented Nov 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy marked this pull request as ready for review November 1, 2025 21:18
@swissspidy swissspidy requested a review from a team as a code owner November 1, 2025 21:18
@swissspidy swissspidy added this to the 2.3.4 milestone Dec 12, 2025
@swissspidy swissspidy merged commit 3b13471 into main Dec 12, 2025
46 checks passed
@swissspidy swissspidy deleted the copilot/add-cron-arguments-logging branch December 12, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add cron arguments into logging

3 participants