Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Dec 23, 2024
1 parent 23ef9ef commit ff20026
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 133 deletions.
14 changes: 13 additions & 1 deletion www/controllers/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function randomColor()
}

/**
* Convertit une durée microtime au format HHhMMmSSs
* Converts a microtime duration to a time format HHhMMmSSs
*/
public static function convertMicrotime(string $duration)
{
Expand All @@ -239,9 +239,21 @@ public static function convertMicrotime(string $duration)
$time .= $seconds . 's';
}

if (empty($time)) {
$time = '0s';
}

return $time;
}

/**
* Converts a microtime to a time format
*/
public static function microtimeToTime(string $microtime)
{
return date('H:i:s', $microtime);
}

/**
* Tri un array par la valeur de clé spécifiée
*/
Expand Down
22 changes: 11 additions & 11 deletions www/controllers/Logging/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function completed(string|null $message = null)
$content['steps'][$name]['end'] = microtime(true);

// Set duration
$content['steps'][$name]['duration'] = \Controllers\Common::convertMicrotime(microtime(true) - $content['steps'][$name]['start']);
$content['steps'][$name]['duration'] = microtime(true) - $content['steps'][$name]['start'];

// Set message if any
if (!empty($message)) {
Expand Down Expand Up @@ -75,21 +75,21 @@ public function error(string $message)
$content['steps'][$name]['end'] = microtime(true);

// Set duration
$content['steps'][$name]['duration'] = \Controllers\Common::convertMicrotime(microtime(true) - $content['steps'][$name]['start']);
$content['steps'][$name]['duration'] = microtime(true) - $content['steps'][$name]['start'];

// Set error-message if not already set
if (empty($content['steps'][$name]['error-message'])) {
$content['steps'][$name]['error-message'] = $message;
}
// Set error-message
$content['steps'][$name]['error-message'] = 'Failed';

// Also set latest sub step on error, unless it has 'completed' status
// Also set latest sub step on error
$subStepName = array_key_last($content['steps'][$name]['substeps']);

if (isset($content['steps'][$name]['substeps'][$subStepName]['status'])) {
if ($content['steps'][$name]['substeps'][$subStepName]['status'] !== 'completed') {
$content['steps'][$name]['substeps'][$subStepName]['status'] = 'error';
$content['steps'][$name]['substeps'][$subStepName]['error-message'] = $message;
}
$content['steps'][$name]['substeps'][$subStepName]['status'] = 'error';
$content['steps'][$name]['substeps'][$subStepName]['output'][] = [
'time' => microtime(true),
'type' => 'error',
'message' => $message
];
}

file_put_contents($this->logFile, json_encode($content));
Expand Down
18 changes: 16 additions & 2 deletions www/controllers/Logging/SubStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function new(string $identifier, array $data)
'title' => '',
'note' => '',
'status' => '',
'start' => microtime(true),
'end' => '',
'duration' => '',
'output' => []
];

Expand Down Expand Up @@ -53,6 +56,12 @@ public function completed(string|null $message = '')
// Set status to completed
$content['steps'][$name]['substeps'][$subName]['status'] = 'completed';

// Set end date
$content['steps'][$name]['substeps'][$subName]['end'] = microtime(true);

// Set duration
$content['steps'][$name]['substeps'][$subName]['duration'] = microtime(true) - $content['steps'][$name]['substeps'][$subName]['start'];

file_put_contents($this->logFile, json_encode($content));

unset($content);
Expand All @@ -63,6 +72,8 @@ public function completed(string|null $message = '')
*/
public function warning(string $message)
{
$this->output($message, 'warning');

$content = $this->getContent();

// Get latest step key name
Expand All @@ -74,8 +85,11 @@ public function warning(string $message)
// Set status to warning
$content['steps'][$name]['substeps'][$subName]['status'] = 'warning';

// Set message
$content['steps'][$name]['substeps'][$subName]['message'] = $message;
// Set end date
$content['steps'][$name]['substeps'][$subName]['end'] = microtime(true);

// Set duration
$content['steps'][$name]['substeps'][$subName]['duration'] = microtime(true) - $content['steps'][$name]['substeps'][$subName]['start'];

file_put_contents($this->logFile, json_encode($content));

Expand Down
Loading

0 comments on commit ff20026

Please sign in to comment.