Commit 3d21f63f authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

add LogEntry class

parent 9dc95366
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
        }
    },
    "require": {
        "php": ">=7.0.0",
        "php": ">=7.4",
        "ext-json": "*",
      "ext-curl": "*"
    },
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ class JobResult
                foreach ($lines as $line){
                    $entry = json_decode($line, true);
                    if($entry){
                        yield $entry;
                        yield new LogEntry($entry);
                    }
                }
            }
+49 −0
Original line number Diff line number Diff line
<?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