
To set up a wc logger, you'll first need to decide on the logging level, which can be set to either debug or info.
The logging level determines the level of detail in the log output, with debug providing more detailed information.
You can configure the logging level by modifying the log_level parameter in the wc logger configuration file.
The configuration file is typically located in the same directory as the wc logger executable.
To configure the wc logger, you'll need to specify the log file path and the log rotation policy.
The log file path determines where the log output will be written, while the log rotation policy determines how often the log file will be rotated.
The log rotation policy can be set to either daily or weekly.
See what others are reading: Google Sheet Script Logger New Log
How to Use
To use the WC Logger, first make sure it's properly installed and configured on your system. This includes setting up the logger to track the correct files and directories.
The WC Logger can be configured to log different types of events, including file creations, modifications, and deletions. You can specify the types of events you want to log and the frequency of logging.
To log events, the WC Logger uses a combination of file system monitoring and system calls. This allows it to capture detailed information about each event, including the timestamp, file path, and user who triggered the event.
You can view the logged events in a variety of formats, including a simple text log or a more detailed JSON output. This makes it easy to analyze and understand the data.
The WC Logger can also be used to track changes to specific files or directories, allowing you to monitor and respond to changes in real-time.
Configuring the Logger
The log handler is registered by default by WooCommerce, so you can define the constant WC_LOG_HANDLER in your wp-config.php to load the desired handler.
To configure the logger, you need to activate WooCommerce Logs, which is usually enabled by default, but double-check by going to WooCommerce > Debug > Logs. If you see a message saying you need to enable logs, just activate the checkbox and hit Save changes.
You can then decide where to store logs - in /uploads/wc-logs/ or in the database, how many days to keep them, and change the minimum severity levels.
Accessing
Accessing the logger is a straightforward process. You can find the WooCommerce Logs under the WooCommerce > Tools > Logs page.
To view the logs, select the log you want to access from the dropdown menu. This will give you a clear picture of what's been happening with your store.
The logs are created daily, keeping them organized and relatively small in size. This is in contrast to a single, ever-growing file.
The logs are stored as files by default, and you can find them in the content/uploads/wc-logs/ directory.
Activating
Activating the logger is the first step to configuring it. To do this, go to WooCommerce > Debug > Logs and check if logs are enabled.
WooCommerce logs are usually enabled by default, but it's worth double checking to make sure. If you don't see a message indicating they're enabled, you'll need to activate them.
Activating the logger is a straightforward process. Simply check the checkbox to enable logs, and then hit "Save changes." More settings will appear on this page, allowing you to customize your logging options.
You can decide where to store logs - either in /uploads/wc-logs/ or in the database.
Configuring the Handler
The Log handler is registered by default by WooCommerce, so you can define the constant WC_LOG_HANDLER in your wp-config.php to load the desired handler.
To configure the Log handler, you can define the constant WC_LOG_HANDLER in your wp-config.php, which will load the desired handler.
WooCommerce provides three default log handlers: WC_Log_Handler_DB, which writes logs to the database, and two others that are described in the documentation.
You can decide where to store logs – in /uploads/wc-logs/ or in the database.
To register custom WooCommerce log handlers, you can use the filter woocommerce_register_log_handlers, which returns the array of instantiated handlers.
Your custom handler must implement the WC_Log_Handler_Interface or extend the WC_Log_Handler class.
For another approach, see: Fl Wc Database
Logging Messages
Logging messages with the WooCommerce Logger is a straightforward process. You can use the wc_get_logger() function to log messages, which is available since WooCommerce 2.7.
The logger has different levels, including debug, that are used to identify the level of severity of a log. The debug() method is used to indicate the 'debug' level, which is the least severity.
To log a message, you can use the following code: wc_get_logger()->debug('Your message here'); This adds a new log to the default log file, named 'log-{YEAR-MONTH-DAY}-{HASH}'.
You can also use other methods like info(), notice(), warning(), and error() to log messages at different levels.
Logging Levels
Logging Levels are a crucial part of the WC_Logger class. There are different log levels available, ranging from Emergency to Debug.
The log levels in WooCommerce Logger include Emergency, Alert, Critical, Error, Warning, Notice, Info, and Debug. Each level has a corresponding method to use for logging messages appropriately.
The log levels are ordered by severity, with Emergency being the highest and Debug being the lowest. This means that Emergency messages take priority over Alert messages, which take priority over Critical messages, and so on.
Here's a breakdown of the log levels:
By default, the WooCommerce Logger is set to log events with a log level of Error or higher. However, you can adjust the log level in the WooCommerce settings to include additional events or reduce the level of logging.
File Management
You can easily get all the available log filenames as an array using WC_Log_Handler_File::get_log_files(). This is a handy feature for developers who need to access log files programmatically.
To write the logs to a file, you can use WC_Log_Handler_File. The logs can be viewed on the WooCommerce admin status page or on the server directory at wp-content/uploads/wc-logs.
File
Writing logs to a file can be done using WC_Log_Handler_File. This method allows you to view the logs on the WooCommerce admin status page.
The logs can be viewed on the WooCommerce admin status page or on the server directory at wp-content/uploads/wc-logs.
Create Product Price Update

When working with file management, it's essential to keep track of updates to product prices in your WooCommerce store. To do this, you can use a trigger to log the changes.
You'll need to identify a trigger, which in this case is the WooCommerce hook trigger "woocommerce_update_product". This trigger is activated after a product is saved.
The WooCommerce function wc_get_logger() can be used to get the log and log the product price details. This function is specifically designed for logging purposes in WooCommerce.
By using this trigger and function, you can automate the process of creating a log entry for product price updates. This can be a huge time-saver and help you stay organized.
Customizing the Logger
You can register custom handlers by using the filter woocommerce_register_log_handlers, which returns the array of instantiated handlers. This is a powerful way to extend the logger's functionality.
To register a custom handler, your code must implement the WC_Log_Handler_Interface or extend the WC_Log_Handler class.
You can also change the debug message source by providing a custom source or using one of the default WooCommerce sources. This can be done by defining the constant WC_LOG_HANDLER in your wp-config.php file.
Here are the steps to register a custom handler:
- Use the filter woocommerce_register_log_handlers to return the array of instantiated handlers
- Implement the WC_Log_Handler_Interface or extend the WC_Log_Handler class in your code
By customizing the logger, you can tailor it to your specific needs and make it more effective for your use case.
Registering Custom Handler
Registering a custom handler is a straightforward process. You can use the filter `woocommerce_register_log_handlers` to register your custom handler.
This filter returns an array of instantiated handlers, so make sure your custom handler is properly instantiated before registering it. Your custom handler must implement the `WC_Log_Handler_Interface` or extend the `WC_Log_Handler` class.
To implement the `WC_Log_Handler_Interface`, you'll need to define the required methods, such as `add_filter` and `process_log`. This will ensure your custom handler is properly integrated with the rest of the logging system.
Remember, registering a custom handler is a great way to tailor the logging behavior to your specific needs.
Change Debug Source
Changing the debug source is a straightforward process. You can generate a custom source by providing one, which will override the automatically generated source.
If you didn't provide a source, it will be generated automatically following a specific pattern, such as plugin-{PLUGIN SLUG}.
You can choose to use one of the default WooCommerce sources instead. This allows you to customize the appearance of your debug messages.
Build Your Custom Event
To build your custom event log, you need to know about the different types of log entry levels, such as "CRITICAL", "error", and "info".
These levels can be used to classify log entries based on their severity level, which can be useful in identifying and troubleshooting issues.
You can define a log entry level by using the syntax "LOG_ENTRY_LEVEL (emergency|alert|critical|error|warning|notice|info|debug)".
For example, you can use "LOG_ENTRY_LEVEL (critical)" to define a critical log entry.
A log entry typically consists of three parts: the log entry level, the log entry content, and the log name.
Here are the three parts you need to define:
- LOG_ENTRY_LEVEL (emergency|alert|critical|error|warning|notice|info|debug)
- LOG_ENTRY_CONTENT (a string to describe the event)
- LOG_NAME (the log name slug e.g. ‘fatal-errors’)
To create a custom event log, you can use the wc_get_logger function and add an entry to your log by defining one of the log entry levels, such as "CRITICAL".
Function Code & Description
The function code and description for customizing the logger is found in the WooCommerce core functions.
The function wc_get_logger resides in woocommerce\includes\wc-core-functions.php, line 1952.
This function gives access to the WooCommerce logging system.
The logging system is written in case there is a Fatal Error (error 5xx) in WordPress.
The errors are also very well described, including the functions that triggered them, hooks involved, references, and lots of information.
Featured Images: pexels.com


