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);
}
esh_import_manual_debug-{date}.log
esh_import_scheduler_debug-{date}.log
esh_import_actualizator_debug-{date}.log
# 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
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
);
$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);
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
);
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'),
]);
}
}
New log file created each day to prevent large files
Logs stored in wp-content/rets-log/ with automatic directory creation
Recommended: Archive logs older than 30 days
Regularly clean old entries from logging tables
Monitor log sizes and error rates for system health
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;
}
}
Manages logging state across admin requests
Queues messages for display in admin interface
Temporary messages shown once to users
[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
[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