Debug Logging

SensAI includes a built-in debug logging system to help developers troubleshoot issues during development and debugging. Debug logging is disabled by default for production sites to keep logs clean and maintain performance.

The debug logging system uses the wpai_enable_debug_logging filter hook to
control whether verbose debug messages are emitted throughout the plugin.

What Gets Logged:

  • Content indexing operations (post saves, batch indexing)
  • API requests and responses
  • Rate limit handling
  • Error conditions and warnings
  • REST API route registration
  • Chat request handling
  • Cache operations
  • Chat history operations

How to enable

↑ Back to top

Add this code to your theme’s functions.php or a custom plugin:

add_filter('wpai_enable_debug_logging', '__return_true');

That’s it! The filter returns true, which enables all debug logging throughout
the plugin.

To disable debug logging, simply remove the filter or change it to:

add_filter('wpai_enable_debug_logging', '__return_false');

Or remove the filter entirely (defaults to false).

Where to find log messages

↑ Back to top

The location of log messages depends on your WordPress debug configuration:

WordPress Debug Log (Recommended)

↑ Back to top

If WP_DEBUG_LOG is enabled in wp-config.php:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Messages will appear in: wp-content/debug.log

Server PHP Error Log

↑ Back to top

If WP_DEBUG_LOG is not enabled, messages follow your server’s PHP error log
settings. Common locations:

  • /var/log/php_errors.log
  • /var/log/apache2/error.log
  • /var/log/nginx/error.log
  • Check your php.ini error_log setting

Custom Error Handler

↑ Back to top

If you have a custom error handler, messages will be routed there.

Example log messages

↑ Back to top

When enabled, you’ll see messages like:

[Timestamp] PHP Notice: WP AI Agent: Registering REST routes for wp-ai-agent/v1
[Timestamp] PHP Notice: WP AI Agent: REST routes registered successfully
[Timestamp] PHP Notice: WP AI Agent: handle_chat_request called
[Timestamp] PHP Notice: WPAI: Starting to index all content
[Timestamp] PHP Notice: WPAI: Checking API status before indexing…
[Timestamp] PHP Warning: WPAI: Rate limit error detected, waiting 60 seconds…
[Timestamp] PHP Notice: WPAI: Finished indexing all content

Best practices

↑ Back to top

Enable only when needed
• Enable debug logging only when troubleshooting
• Disable in production to keep logs clean
• Remove the filter when done debugging

Use WP_DEBUG_LOG
• Enable WP_DEBUG_LOG in wp-config.php
• Set WP_DEBUG_DISPLAY to false (don’t show on frontend)
• Check wp-content/debug.log for messages

Monitor log size
• Debug logs can grow large quickly
• Regularly check and rotate log files
• Consider log rotation tools

Security considerations
• Debug logs may contain sensitive information
• Don’t enable on production sites accessible to public
• Secure your debug.log file (add to .htaccess if needed)

Conditional enabling
You can enable logging conditionally:

// Only enable for specific user or in development
add_filter('wpai_enable_debug_logging', function() {
// Enable only for admin users
return current_user_can('manage_options');
// Or enable only in development
// return defined('WP_DEBUG') && WP_DEBUG;
});

Troubleshooting common scenarios

↑ Back to top

Content not being indexed
Enable logging and check for:
• “WPAI: Starting to index all content”
• “WPAI: Failed to index post X”
• API key errors
• Rate limit messages

Chat not working
Enable logging and check for:
• “WP AI Agent: Registering REST routes”
• “WP AI Agent: handle_chat_request called”
• API connection errors
• Missing parameter warnings

API rate limits
Look for:
• “WPAI: Rate limit error detected”
• Automatic retry messages
• Wait time notifications

Cache issues
Check for:
• Cache hit/miss messages
• Cache expiration notices
• Cache clearing operations