How to Use LogWatch to Debug Errors in CMS Made Simple

General project discussion. NOT for help questions.
Post Reply
User avatar
magallo
Dev Team Member
Dev Team Member
Posts: 121
Joined: Thu Mar 24, 2011 12:37 am

How to Use LogWatch to Debug Errors in CMS Made Simple

Post by magallo »

How to Use LogWatch to Debug Errors in CMS Made Simple

Debugging errors in a web application can be a challenging task, especially when multiple modules and components are involved. To simplify this process in CMS Made Simple, we've created a module called LogWatch. In this blog post, we'll guide you through the steps to use LogWatch to effectively capture and debug errors throughout your CMS Made Simple application.

What is LogWatch?

LogWatch is a CMS Made Simple module designed to log server error messages. It captures errors triggered by any part of the application, including other modules, and logs them in a systematic and accessible way. This helps developers identify and fix issues quickly.

Advantages of Using LogWatch

When encountering 500 (Internal Server Error) messages, using LogWatch offers significant advantages. A 500 error can be caused by various issues, such as server misconfigurations, code errors, or resource limitations. LogWatch helps you pinpoint the exact cause of these errors by providing detailed logs that include the error type, file, line number, and stack trace. This information is crucial for diagnosing and resolving issues quickly, minimizing downtime and improving the overall stability of your website.

Here’s an example of a 500 (Internal Server Error) message displayed in the browser console:

Image

And here’s how the LogWatch module logs this error in the admin dashboard, providing detailed information for debugging:

Image

Setting Up LogWatch

First, you need to install and enable the LogWatch module. You can download the module from the CMS Made Simple module repository or your preferred source.

1. Download and Install LogWatch:
- Go to the Admin Panel -> Extensions -> Modules.
- Install the LogWatch module.

2. Initialize LogWatch:
The module initializes itself to start logging errors as soon as it is installed and enabled. This is done by setting up an error handler that captures all errors throughout the application lifecycle.

How LogWatch Works

LogWatch sets up a global error handler that catches errors from all modules and parts of the application. Here’s a brief overview of the implementation:

1. Global Error Handler Initialization:
LogWatch initializes the `LogIt` class during the frontend initialization process. This ensures that the error handler is set up early and captures all subsequent errors.

2. Static Initialization Check:
To avoid multiple initializations, a static variable is used to ensure the `LogIt` class is only initialized once per request. This prevents infinite loops and redundant logging setups.

3. Autoloading and Integration:
The module integrates with Smarty and uses an autoloader to ensure the `LogIt` class is available and ready to handle errors.

Using LogWatch

Once LogWatch is set up, it automatically logs errors to a designated file or storage system. Here’s how you can use it:

1. Trigger Errors:
To test LogWatch, you can deliberately trigger errors in your templates or custom user-defined tags (UDTs). For example:

Code: Select all

   // Create a UDT to test error logging
   function smarty_cms_function_my_test_udt($params, &$smarty) {
       // Trigger a user notice
       trigger_error('This is a test notice from UDT', E_USER_NOTICE);
   }
   
Call this UDT in your template:

Code: Select all

   {my_test_udt}
   
2. Check the Logs:
LogWatch logs errors to a dedicated dashboard found at Admin Panel -> Site Admin -> LogWatch. You can check logged errors and their details:
- Error type
- File and line number where the error occurred
- Error message
- Stack trace (if available)

3. Analyze and Debug:
Use the logged information to identify and fix issues in your code. The detailed error messages and stack traces provide valuable insights into what went wrong and where.

Conclusion

LogWatch is a powerful tool for developers using CMS Made Simple. By capturing and logging errors globally, it simplifies the debugging process and helps maintain a stable and error-free application. Install LogWatch today and take control of error management in your CMS Made Simple projects.

We hope this guide helps you get started with LogWatch. Happy debugging!

Feedback/Support
This module does not include commercial support. However, there are a number of resources available to help you with it:
  • For the latest version of this module or to file a Feature Request or Bug Report, please visit the LogWatch GitHub Page.
  • If you didn't find an answer to your question, you are warmly invited to open a new issue on the LogWatch GitHub Issues Page.
Magal Hezi
Pixel Solutions, Technology Partners
magal@pixelsolutions.biz | pixelsolutions.biz

Image
Post Reply

Return to “General Discussion”