Commit 3d21f63f authored by Mickael Desfrenes's avatar Mickael Desfrenes
Browse files

add LogEntry class

parent 9dc95366
......@@ -10,7 +10,7 @@
}
},
"require": {
"php": ">=7.0.0",
"php": ">=7.4",
"ext-json": "*",
"ext-curl": "*"
},
......
......@@ -37,7 +37,7 @@ class JobResult
foreach ($lines as $line){
$entry = json_decode($line, true);
if($entry){
yield $entry;
yield new LogEntry($entry);
}
}
}
......
<?php
declare(strict_types=1);
namespace Certic\Circe;
class LogEntry
{
const LEVEL_DEBUG = 0;
const LEVEL_INFO = 1;
const LEVEL_WARNING = 2;
const LEVEL_ERROR = 3;
const LEVEL_FATAL = 4;
private array $log_dict;
public function __construct(array $log_dict){
$this->log_dict = $log_dict;
}
public function getTimestamp(): \DateTime{
// "%Y-%m-%dT%H:%M:%S.%fZ"
if(array_key_exists('timestamp', $this->log_dict)){
return new \DateTime($this->log_dict['timestamp']);
}
}
public function getMessage(): string{
if(array_key_exists('message', $this->log_dict)){
return $this->log_dict['message'];
}
}
public function getLevel(): int{
if(array_key_exists('level', $this->log_dict)){
switch ($this->log_dict['level']){
case 'DEBUG':
return self::LEVEL_DEBUG;
case 'WARNING':
return self::LEVEL_WARNING;
case 'ERROR':
return self::LEVEL_ERROR;
case 'FATAL':
case 'CRITICAL':
return self::LEVEL_FATAL;
default:
return self::LEVEL_INFO;
}
}
return self::LEVEL_INFO;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment