LOGGING SYSTEM

Comprehensive Import Monitoring & Debugging

Core Logging Implementation

Debug Logging Function

private function log_debug($message, $mode = '') {
    $log_dir = WP_CONTENT_DIR . '/rets-log';
    $log_file = $log_dir . '/esh_import_manual_debug-' . date('Y-m-d') . '.log';
    
    if ($mode == 'actualizer') {
        $log_file = $log_dir . '/esh_import_actualizator_debug-' . date('Y-m-d') . '.log';
    } elseif ($mode == 'scheduler') {
        $log_file = $log_dir . '/esh_import_scheduler_debug-' . date('Y-m-d') . '.log';
    }

    // Create directory if it doesn't exist
    if (!is_dir($log_dir)) {
        wp_mkdir_p($log_dir);
    }

    $timestamp = date('Y-m-d H:i:s');
    file_put_contents($log_file, "[$timestamp] $message\n", FILE_APPEND);
}

Log File Structure

Manual Imports

esh_import_manual_debug-{date}.log

Scheduled Imports

esh_import_scheduler_debug-{date}.log

Actualizer Imports

esh_import_actualizator_debug-{date}.log

Log Entry Format

# Example Log Entries

[2024-08-19 10:30:15] [123] Will fetch 5 images for post_id: 456
[2024-08-19 10:30:17] [123] Success to get contents from URL: http://...
[2024-08-19 10:30:20] [123] Successfully uploaded image for post_id: 456
[2024-08-19 10:30:22] [123] Failed upload images for post_id: 789 (3 images)

# Format: [timestamp] [schedule_id] message

Database Logging Tables

RETS Server Request Log

CREATE TABLE rets_server_request_log (
    id INT AUTO_INCREMENT PRIMARY KEY,
    rets_query TEXT,
    message TEXT,
    query_result LONGTEXT,
    schedule_id INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Usage Example

$pp_log_sql = "INSERT INTO rets_server_request_log SET rets_query='" . addslashes($query) . "', message='try', query_result='" . addslashes($body) . "', schedule_id=" . $current_schedule_id; $wpdb->query($pp_log_sql);

Property Schedule Log

CREATE TABLE property_schedule_log (
    id INT AUTO_INCREMENT PRIMARY KEY,
    post_id BIGINT(20),
    schedule_id INT,
    rets_data LONGTEXT,
    message TEXT,
    L_ListingDate DATE,
    offset INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Tracks Import Operations

  • • Property creation/update status
  • • Complete RETS data snapshots
  • • Schedule execution context
  • • Import offset tracking

Failed Upload Tracking

protected function save_post_failed_upload($post_id, $schedule_id, $mode) {
    global $wpdb;
    $table_name = $wpdb->prefix . 'post_failed_uploads';

    // Check if entry exists
    $existing_entry = $wpdb->get_row(
        $wpdb->prepare("SELECT * FROM $table_name WHERE post_id = %d", $post_id)
    );

    if ($existing_entry) {
        // Increment retry count
        $wpdb->update($table_name, [
            'retry' => $existing_entry->retry + 1,
            'update_date' => current_time('mysql'),
        ], ['id' => $existing_entry->id]);
    } else {
        // Insert new failed upload record
        $wpdb->insert($table_name, [
            'post_id' => $post_id,
            'schedule_id' => $schedule_id,
            'mode' => $mode,
            'retry' => 0,
            'processing' => 0,
            'create_date' => current_time('mysql'),
        ]);
    }
}

Logging Categories & Levels

Error Level Logging

Image Processing Errors

  • • Failed to get contents from URL
  • • Invalid image content validation
  • • AWS S3 upload failures
  • • RETS object retrieval errors

Import Failures

  • • RETS connection timeouts
  • • Property creation errors
  • • Field mapping failures
  • • Database insert/update errors

Warning Level Logging

Data Quality Issues

  • • Missing required fields
  • • Invalid URL formats
  • • Skipped image uploads
  • • Duplicate property handling

Performance Warnings

  • • High retry counts
  • • Memory usage spikes
  • • Long execution times
  • • Rate limiting triggers

Info Level Logging

Import Progress

  • • Properties processed count
  • • Images downloaded successfully
  • • Schedule execution start/end
  • • Queue processing updates

System Status

  • • RETS connection established
  • • AWS S3 upload success
  • • Category/tag creation
  • • Field mapping updates

Debug Level Logging

Detailed Tracing

  • • Function entry/exit points
  • • Variable values and states
  • • API request/response data
  • • Image processing steps

Development Info

  • • SQL queries executed
  • • Memory usage snapshots
  • • Execution timing data
  • • Configuration values

Log Management & Maintenance

File Management

Daily Log Files

New log file created each day to prevent large files

/wp-content/rets-log/
├── esh_import_manual_debug-2024-08-19.log
├── esh_import_scheduler_debug-2024-08-19.log
└── esh_import_actualizator_debug-2024-08-19.log

Directory Structure

Logs stored in wp-content/rets-log/ with automatic directory creation

Maintenance Tasks

Log Rotation

Recommended: Archive logs older than 30 days

Database Cleanup

Regularly clean old entries from logging tables

Monitoring

Monitor log sizes and error rates for system health

WordPress Integration

Esh_Rets_Logger Class

function esh_get_rets_logger() {
    return apply_filters('es_get_rets_logger', new Esh_Rets_Logger);
}

class Esh_Rets_Logger extends Esh_Messenger {
    public function set_message($msg, $type = 'info') {
        // Store messages in session or database
        $this->messages[] = [
            'msg' => $msg,
            'type' => $type,
            'timestamp' => current_time('timestamp')
        ];
    }
    
    public function get_messages() {
        return $this->messages;
    }
}

Session Storage Integration

Esh_Session_Storage

Manages logging state across admin requests

Message Queuing

Queues messages for display in admin interface

Flash Messages

Temporary messages shown once to users

Troubleshooting with Logs

Common Error Patterns

Image Upload Failures

[2024-08-19 10:30:15] Failed to get contents from URL: http://... [2024-08-19 10:30:16] Invalid URL: http://malformed-url [2024-08-19 10:30:17] Exception occurred: AWS S3 permission denied

RETS Connection Issues

[2024-08-19 10:30:15] RETS Login failed: Invalid credentials [2024-08-19 10:30:16] Connection timeout after 30 seconds [2024-08-19 10:30:17] GetObject failed: Resource not found

Performance Monitoring

Import Statistics

  • • Properties processed per minute
  • • Average image download time
  • • Memory usage patterns
  • • Error rates by import type

System Health Indicators

  • • Queue processing rates
  • • Failed upload trends
  • • RETS server response times
  • • Schedule execution success rates
← Return to Main Documentation