fix(logs): convert timestamps to server timezone in deployment and container logs

This commit is contained in:
ShadowArcanist 2026-05-13 01:48:14 +05:30
parent 9590f144bd
commit bf10b45bbc
No known key found for this signature in database
2 changed files with 21 additions and 15 deletions

View file

@ -200,6 +200,7 @@ function decode_remote_command_output(?ApplicationDeploymentQueue $application_d
} }
$application = Application::find(data_get($application_deployment_queue, 'application_id')); $application = Application::find(data_get($application_deployment_queue, 'application_id'));
$is_debug_enabled = data_get($application, 'settings.is_debug_enabled'); $is_debug_enabled = data_get($application, 'settings.is_debug_enabled');
$serverTimezone = getServerTimezone(data_get($application, 'destination.server'));
$logs = data_get($application_deployment_queue, 'logs'); $logs = data_get($application_deployment_queue, 'logs');
if (empty($logs)) { if (empty($logs)) {
@ -240,8 +241,14 @@ function decode_remote_command_output(?ApplicationDeploymentQueue $application_d
return $formatted return $formatted
->sortBy(fn ($i) => data_get($i, 'order')) ->sortBy(fn ($i) => data_get($i, 'order'))
->map(function ($i) { ->map(function ($i) use ($serverTimezone) {
data_set($i, 'timestamp', Carbon::parse(data_get($i, 'timestamp'))->format('Y-M-d H:i:s.u')); $timestamp = Carbon::parse(data_get($i, 'timestamp'));
try {
$timestamp->setTimezone($serverTimezone);
} catch (\Exception) {
$timestamp->setTimezone('UTC');
}
data_set($i, 'timestamp', $timestamp->format('Y-M-d H:i:s.u'));
return $i; return $i;
}) })

View file

@ -520,20 +520,19 @@ class="text-gray-500 dark:text-gray-400 py-2">
// Parse timestamp from log line (ISO 8601 format: 2025-12-04T11:48:39.136764033Z) // Parse timestamp from log line (ISO 8601 format: 2025-12-04T11:48:39.136764033Z)
$timestamp = ''; $timestamp = '';
$logContent = $line; $logContent = $line;
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}:\d{2}:\d{2})(?:\.(\d+))?Z?\s(.*)$/', $line, $matches)) { if (preg_match('/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d+))?Z?\s(.*)$/', $line, $matches)) {
$year = $matches[1]; $microseconds = isset($matches[2]) ? substr($matches[2], 0, 6) : '000000';
$month = $matches[2]; $logContent = $matches[3];
$day = $matches[3];
$time = $matches[4];
$microseconds = isset($matches[5]) ? substr($matches[5], 0, 6) : '000000';
$logContent = $matches[6];
// Convert month number to abbreviated name // Convert UTC Docker timestamp to server timezone for display
$monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; $carbonTs = \Carbon\Carbon::parse($matches[1], 'UTC');
$monthName = $monthNames[(int)$month - 1] ?? $month; $serverTz = getServerTimezone($server);
try {
// Format for display: 2025-Dec-04 09:44:58 $carbonTs->setTimezone($serverTz);
$timestamp = "{$year}-{$monthName}-{$day} {$time}"; } catch (\Exception) {
// keep UTC
}
$timestamp = $carbonTs->format('Y-M-d H:i:s');
// Include microseconds in key for uniqueness // Include microseconds in key for uniqueness
$lineKey = "{$timestamp}.{$microseconds}"; $lineKey = "{$timestamp}.{$microseconds}";
} }