nur-sery/nur_tbin/log.php

87 lines
2.6 KiB
PHP
Executable File

#!/usr/bin/php
<?php # -*- coding: utf-8 mode: php -*- vim:sw=2:sts=2:et:ai:si:sta:fenc=utf-8
require(__DIR__.'/../vendor/autoload.php');
use nur\A;
use nur\b\ValueException;
use nur\cli\Application;
use nur\log;
Application::run(new class extends Application {
const ARGS = [
"merge" => Application::ARGS,
["-l:", "--level"],
["-t:", "--type"],
["-r:", "--result"],
];
private $args;
private $level, $type, $result;
const LEVEL_MAP = [
"1" => log::CRITICAL, "X" => log::CRITICAL,
"2" => log::MAJOR, "M" => log::MAJOR,
"3" => log::NORMAL, "n" => log::NORMAL,
"4" => log::MINOR, "m" => log::MINOR,
];
const TYPE_MAP = [
"1" => log::ERROR, "e" => log::ERROR,
"2" => log::WARNING, "w" => log::WARNING,
"3" => log::INFO, "i" => log::INFO,
"4" => log::DEBUG, "d" => log::DEBUG,
];
const RESULT_MAP = [
"0" => log::NONE, "n" => log::NONE,
"1" => log::NEUTRAL, "s" => log::NEUTRAL,
"2" => log::SUCCESS, "ok" => log::SUCCESS,
"3" => log::FAILURE, "ko" => log::FAILURE,
];
function main() {
log::info("Profil sélectionné: ".self::profile());
log::action("calcul des arguments");
$level = A::get(self::LEVEL_MAP, $this->level, log::NORMAL);
$type = A::get(self::TYPE_MAP, $this->type, log::INFO);
$result = A::get(self::RESULT_MAP, $this->result, log::NONE);
log::asuccess();
if ($this->args) {
$log = log::get();
foreach($this->args as $message) {
$log->addMessage($message, $type + $result, $level);
}
} else {
log::error("error message");
log::warning("warning message");
log::note("note message");
log::info("info message");
log::step("step message");
log::success("success message");
log::failure("failure message");
log::debug("debug message");
log::group("action multiple 1");
log::step("étape 1");
log::asuccess("effectué avec succès");
log::group("action multiple 2");
log::step("étape 2.1");
log::step("étape 2.2");
log::afailure("erreur d'étape");
log::action("fonction sans valeur de retour", function () {
echo "sortie de la fonction sans valeur de retour\n";
});
log::action("fonction true", function () {
return true;
});
log::action("fonction false", function () {
return false;
});
log::action("fonction string", function () {
return "résultat de la fonction string";
});
log::action("fonction exception", function () {
throw new ValueException("message de l'exception");
});
}
}
});