Skip to content

Conversation

@tijmenbruggeman
Copy link
Collaborator

@tijmenbruggeman tijmenbruggeman commented Jan 6, 2026

We had two customers reporting two different issues which we could not figure out. Often times this is due to setup configurations but it is hard to figure out.

Having some diagnostics and logs should make it easier to troubleshoot these issues.

This PR will also:

  • set the timeout for the entire request to 120 seconds
  • set the timeout to connect to the server to 8 seconds

Good to know

  • Max 2MB log file, if limit is reached, old log will be deleted and new one will be created. This is the simplest method and prevents from adding rotation;
  • Turn on logs will clear any previous logs;
  • Requires ziparchive to download;
  • No sensitive data will be logged;
  • Logging will slow down performance as it will open and write the log entry each time something compresses;

Screenshots
Screenshot 2026-01-06 at 16 51 45
Customers can turn on logging and download a diagnostics zip file from within settings

image _Logs are formatted nicely_

@rkoopmans rkoopmans requested a review from Copilot January 12, 2026 13:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds logging and diagnostics capabilities to help troubleshoot customer issues. It introduces a file-based logger with automatic rotation at 2MB, a diagnostics export feature that bundles logs and system information into a downloadable zip file, and sets API request timeouts (120s total, 8s connect) to prevent indefinite hanging.

Changes:

  • Introduced Tiny_Logger singleton for file-based logging with 2MB rotation
  • Added Tiny_Diagnostics class to collect system info and generate downloadable diagnostics zip files
  • Integrated logging calls throughout the compression workflow
  • Added settings UI for enabling/disabling logging and downloading diagnostics

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
tiny-compress-images.php Added requires for new logger and diagnostics classes
test/unit/TinySettingsAjaxTest.php Refactored test to use new assertHook helper method
test/unit/TinySettingsAdminTest.php Added test for new logging_enabled setting registration
test/unit/TinyLoggerTest.php Added comprehensive tests for logger singleton, file creation, rotation, and enable/disable behavior
test/unit/TinyDiagnosticsTest.php Added tests for diagnostics action hook and info collection
test/helpers/wordpress.php Added assertHook helper, WordPressMocks class with mock WordPress functions, and formatting updates
src/views/settings.php Included new diagnostics settings partial
src/views/settings-diagnostics.php New view for logging toggle and diagnostics download button
src/js/admin.js Added AJAX handler for diagnostics download
src/css/admin.css Added utility classes for diagnostics UI
src/class-tiny-settings.php Instantiated diagnostics and registered logging_enabled setting
src/class-tiny-plugin.php Initialized logger and added debug logging throughout compression flow
src/class-tiny-logger.php New singleton logger with file rotation and WordPress option integration
src/class-tiny-image.php Added detailed debug and error logging for compression operations
src/class-tiny-diagnostics.php New class for collecting and exporting diagnostic information
src/class-tiny-compress-fopen.php Added debug logging for fopen compression responses
src/class-tiny-compress-client.php Added timeout constants, error logging, and applied timeout settings to client

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add comprehensive test for nonce verification in the download_diagnostics
AJAX endpoint. The test verifies that check_ajax_referer is called with the
correct parameters and that wp_die is invoked when nonce verification fails.

Also:
- Add check_ajax_referer and wp_die mock implementations to WordPress test helpers
- Add wp_json_encode mock for test compatibility
- Rename test file to match class name convention (Tiny_Diagnostics_Test.php)
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.

3 participants