From d581512171ec82c670f3fae634f339f594a28896 Mon Sep 17 00:00:00 2001 From: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Date: Wed, 28 Feb 2024 03:31:31 -0800 Subject: [PATCH] Logging: Improve compatibility with multisite (#44735) * Add static method for getting the log directory * Add filter for customizing the log directory path * Handle case where constant is already defined * Do directory creation on the fly instead of during install * Replace all Core usages of WC_LOG_DIR * Ensure each site's log handler setting is respected * Add unit tests * Fix legacy logger unit tests * Update docs * Regenerate docs manifest file (required by GitHub CI) --------- Co-authored-by: Nestor Soriano --- docs/docs-manifest.json | 9 +-- docs/extension-development/logging.md | 2 +- .../changelog/try-log-file-multisite | 4 ++ .../views/html-admin-page-status-logs.php | 8 ++- .../views/html-admin-page-status-report.php | 10 ++- .../woocommerce/includes/class-wc-install.php | 10 --- .../woocommerce/includes/class-wc-logger.php | 51 ++++++++++---- .../includes/class-woocommerce.php | 13 +++- .../class-wc-log-handler-file.php | 27 +++++--- ...ss-wc-rest-system-status-v2-controller.php | 5 +- .../includes/wc-deprecated-functions.php | 2 +- .../Admin/Logging/FileV2/FileController.php | 32 +++------ .../src/Internal/Admin/Logging/Settings.php | 57 +++++++++++++--- .../woocommerce/src/Utilities/LoggingUtil.php | 9 +++ .../unit-tests/log/log-handler-file.php | 4 +- .../tests/legacy/unit-tests/log/logger.php | 26 +++++--- .../util/class-wc-tests-core-functions.php | 2 +- .../Logging/FileV2/FileControllerTest.php | 36 +++++----- .../Admin/Logging/FileV2/FileTest.php | 33 +++++----- .../Admin/Logging/LogHandlerFileV2Test.php | 22 +++---- .../Internal/Admin/Logging/SettingsTest.php | 66 ++++++++++++++++++- 21 files changed, 291 insertions(+), 137 deletions(-) create mode 100644 plugins/woocommerce/changelog/try-log-file-multisite diff --git a/docs/docs-manifest.json b/docs/docs-manifest.json index 3c1263fd490..92808bf5e37 100644 --- a/docs/docs-manifest.json +++ b/docs/docs-manifest.json @@ -350,7 +350,7 @@ { "post_title": "Logging in WooCommerce", "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/extension-development/logging.md", - "hash": "2cb0d0d594481127d144a95ccf8ca8ca826711dbf25a42fdc69a75c7d200d99f", + "hash": "7f5777df46d83e49b024ae205111e0a0960d8c53466d351a8744999d256cb0c0", "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/extension-development/logging.md", "id": "c684e2efba45051a4e1f98eb5e6ef6bab194f25c" }, @@ -916,11 +916,6 @@ ], "categories": [] }, - { - "category_slug": "utilities", - "category_title": "Utilities", - "categories": [] - }, { "content": "\nThis section covers general guidelines, and best practices to follow in order to ensure your product experience aligns with WooCommerce for ease of use, seamless integration, and strong adoption.\n\nWe strongly recommend you review the current [WooCommerce setup experience](https://woo.com/documentation/plugins/woocommerce/getting-started/) to get familiar with the user experience and taxonomy.\n\nWe also recommend you review the [WordPress core guidelines](https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/) to ensure your product isn't breaking any rules, and review [this helpful resource](https://woo.com/document/grammar-punctuation-style-guide/) on content style.\n\n## General\n\nUse existing WordPress/WooCommerce UI, built in components (text fields, checkboxes, etc) and existing menu structures.\n\nPlugins which draw on WordPress' core design aesthetic will benefit from future updates to this design as WordPress continues to evolve. If you need to make an exception for your product, be prepared to provide a valid use case.\n\n- [WordPress Components library](https://wordpress.github.io/gutenberg/?path=/story/docs-introduction--page)\n- [Figma for WordPress](https://make.wordpress.org/design/2018/11/19/figma-for-wordpress/) | ([WordPress Design Library Figma](https://www.figma.com/file/e4tLacmlPuZV47l7901FEs/WordPress-Design-Library))\n- [WooCommerce Component Library](https://woocommerce.github.io/woocommerce-admin/)\n", "category_slug": "user-experience-extensions", @@ -1209,5 +1204,5 @@ "categories": [] } ], - "hash": "a485b51014a2262571751ae495976ca40aa8ffd4fddc7ee8ca8171ee51bd8984" + "hash": "2453d3ac64b6f1f4f4cd8efddfc166602f7182a9dff17218070fd2dccf8722e5" } \ No newline at end of file diff --git a/docs/extension-development/logging.md b/docs/extension-development/logging.md index e3a651410a4..16fe42ace5a 100644 --- a/docs/extension-development/logging.md +++ b/docs/extension-development/logging.md @@ -48,7 +48,7 @@ Uncheck the box here to turn off all logging. This is not recommended in most ci Out-of-the-box, WooCommerce has two different log storage methods available: -* **File system** - Log entries are recorded to files. Files are differentiated by the `source` value for the log entry (see the "Adding logs" section below), and by the current date. The files are stored in `wp-content/uploads/wc-logs`, but this can be changed by defining the `WC_LOG_DIR` constant in your `wp-config.php` file with a custom path. Log files can be up to 5 MB in size, after which the log file will rotate. +* **File system** - Log entries are recorded to files. Files are differentiated by the `source` value for the log entry (see the "Adding logs" section below), and by the current date. The files are stored in the `wc-logs` subdirectory of the site's `uploads` directory. A custom directory can be defined using the `woocommerce_log_directory` filter hook. Log files can be up to 5 MB in size, after which the log file will rotate. * **Database** - Log entries are recorded to the database, in the `{$wpdb->prefix}woocommerce_log` table. If you change this setting, and you already have some log entries, those entries will not be migrated to the other storage method, but neither will they be deleted. diff --git a/plugins/woocommerce/changelog/try-log-file-multisite b/plugins/woocommerce/changelog/try-log-file-multisite new file mode 100644 index 00000000000..bc31145fa67 --- /dev/null +++ b/plugins/woocommerce/changelog/try-log-file-multisite @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Improve compatibility of the logging system with multisite diff --git a/plugins/woocommerce/includes/admin/views/html-admin-page-status-logs.php b/plugins/woocommerce/includes/admin/views/html-admin-page-status-logs.php index 443d17864dc..6a40c1eb9d0 100644 --- a/plugins/woocommerce/includes/admin/views/html-admin-page-status-logs.php +++ b/plugins/woocommerce/includes/admin/views/html-admin-page-status-logs.php @@ -5,10 +5,14 @@ * @package WooCommerce\Admin\Logs */ +use Automattic\WooCommerce\Utilities\LoggingUtil; + if ( ! defined( 'ABSPATH' ) ) { exit; } +$log_directory = LoggingUtil::get_log_directory(); + ?>
@@ -25,7 +29,7 @@ if ( ! defined( 'ABSPATH' ) ) {