From aa1eae6c178491e1a11bacdbb2d0b1f9f2cdf25a Mon Sep 17 00:00:00 2001 From: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:11:08 -0700 Subject: [PATCH] Docs: Updates to the Logging doc (#49430) * Docs: Updates to the Logging doc This tweaks the wording in a few places and adds a new suggestion under the "Customizing" header about changing the directory where log files are stored. * Update docs manifest --- docs/docs-manifest.json | 9 +++++++-- docs/extension-development/logging.md | 10 +++++++--- plugins/woocommerce/changelog/update-logging-doc | 5 +++++ 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 plugins/woocommerce/changelog/update-logging-doc diff --git a/docs/docs-manifest.json b/docs/docs-manifest.json index 7165e486669..e8ed7991206 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": "844689b6d9c482fb217a512db6ddab0afd4d76b2b9e378a9302681d2a8dfe517", + "hash": "7e66b9ea605944c5926cf6099fb8fb323976c014fef7dd768c91cef17b091edd", "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/extension-development/logging.md", "id": "c684e2efba45051a4e1f98eb5e6ef6bab194f25c" }, @@ -1068,6 +1068,11 @@ ], "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://woocommerce.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://woocommerce.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", @@ -1367,5 +1372,5 @@ "categories": [] } ], - "hash": "051ee4cdae51c1d92f1a5da2df9eafe45b32ce571b51bf6fe8d48f8dc29ff36d" + "hash": "0f3a825397f5872c1f482a1402a07e71002b2aceec65845f60545f17d7a1d6ff" } \ No newline at end of file diff --git a/docs/extension-development/logging.md b/docs/extension-development/logging.md index a1e7298161b..dcedb9dc5e1 100644 --- a/docs/extension-development/logging.md +++ b/docs/extension-development/logging.md @@ -140,9 +140,9 @@ wc_get_logger()->info( ### Best practices -* Rather than using the `WC_Logger`‘s `log()` method directly, it's better to use one of the wrapper methods that's specific to the log level. E.g. `info()` or `error()`. +* Rather than using the `WC_Logger`'s `log()` method directly, it's better to use one of the wrapper methods that's specific to the log level. E.g. `info()` or `error()`. * Write a message that is a complete, coherent sentence. This will make it more useful for people who aren't familiar with the codebase. -* Log messages should not be translatable (see the discussion about this in the comments). Keeping the message in English makes it easier to search for solutions based on the message contents, and also makes it easier for Happiness Engineers to understand what's happening, since they may not speak the same language as the site owner. +* Log messages should not be translatable. Keeping the message in English makes it easier to search for solutions based on the message contents, and also makes it easier for anyone troubleshooting to understand what's happening, since they may not speak the same language as the site owner. * Ideally, each log entry message should be a single line (i.e. no line breaks within the message string). Additional lines or extra data should be put in the context array. * Avoid outputting structured data in the message string. Put it in a key in the context array instead. The logger will handle converting it to JSON and making it legible in the log viewer. * If you need to include a stack trace, let the logger generate it for you. @@ -159,7 +159,7 @@ The `WC_Logger` class can be substituted for another class via the `woocommerce_ In WooCommerce, a log handler is a PHP class that takes the raw log data and transforms it into a log entry that can be stored or dispatched. WooCommerce ships with four different log handler classes: -* `Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2`: This is the default handler, representing the "file system" log storage method. It records log entries to files. +* `Automattic\\WooCommerce\\Internal\\Admin\\Logging\\LogHandlerFileV2`: This is the default handler, representing the "file system" log storage method. It records log entries to files. * `WC_Log_Handler_File`: This is the old default handler that also records log entries to files. It may be deprecated in the future, and it is not recommended to use this class or extend it. * `WC_Log_Handler_DB`: This handler represents the "database" log storage method. It records log entries to the database. * `WC_Log_Handler_Email`: This handler does not store log entries, but instead sends them as email messages. Emails are sent to the site admin email address. This handler has [some limitations](https://github.com/woocommerce/woocommerce/blob/fe81a4cf27601473ad5c394a4f0124c785aaa4e6/plugins/woocommerce/includes/log-handlers/class-wc-log-handler-email.php#L15-L27). @@ -185,6 +185,10 @@ add_filter( 'woocommerce_register_log_handlers', 'my_wc_log_handlers' ); You may want to create your own log handler class in order to send logs somewhere else, such as a Slack channel or perhaps an InfluxDB instance. Your class must extend the [`WC_Log_Handler`](https://woocommerce.github.io/code-reference/classes/WC-Log-Handler.html) abstract class and implement the [`WC_Log_Handler_Interface`](https://woocommerce.github.io/code-reference/classes/WC-Log-Handler-Interface.html) interface. The [`WC_Log_Handler_Email`](https://github.com/woocommerce/woocommerce/blob/6688c60fe47ad42d49deedab8be971288e4786c1/plugins/woocommerce/includes/log-handlers/class-wc-log-handler-email.php) handler class provides a good example of how to set this up. +### Log file storage location + +When using the "file system" log handler, by default the log files are stored in the `wc-logs` subdirectory of the WordPress `uploads` directory, which means they might be publicly accessible. WooCommerce adds an `.htaccess` file to prevent access to `wc-logs`, but not all web servers recognize that file. If you have the option, you may want to consider storing your log files in a directory outside of the web root. Make sure the directory has the same user/group permissions as the `uploads` directory so that WordPress can access it. Then use the `woocommerce_log_directory` filter hook to set the path to your custom directory. + ### Turning off noisy logs If there is a particular log that is recurring frequently and clogging up your log files, you should probably figure out why it keeps getting triggered and resolve the issue. However, if that's not possible, you can add a callback to the `woocommerce_logger_log_message` filter hook to ignore that particular log while still allowing other logs to get through: diff --git a/plugins/woocommerce/changelog/update-logging-doc b/plugins/woocommerce/changelog/update-logging-doc new file mode 100644 index 00000000000..9ed64dbffad --- /dev/null +++ b/plugins/woocommerce/changelog/update-logging-doc @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: Update developer doc about logging + +