1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| <?php
require 'vendor/autoload.php';
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
class loggerPerso {
private $logger;
public function __construct($path = __DIR__,$nameFiles = '/app.log',$channelName = 'default'){
$this->logger = new Logger($channelName);
$this->logger->pushHandler(new StreamHandler($path.$nameFiles, Logger::WARNING));
}
public function logs($message = "NNOTHING",$info = "INFO") {
echo $info." -- ".$message."\n";
if($info == "ERROR"){
$this->logger->error($message);
} else if ($info == "WARNING"){
$this->logger->warning($message);
} else {
$this->logger->info($message);
}
}
public function testLog(){
$this->logs("test log ERROR","ERROR");
$this->logs("test log ERROR","WARNING");
$this->logs("test log ERROR");
}
}
class voiture extends loggerPerso {
public $name = "";
public $logger ="";
public function __construct() {
parent::__construct();
$this->logs("Création d'une voiture");
}
function getName () {
$this->logs("Affichage du nom");
return $this->name;
}
function setName($name){
$this->logs("Le nom est setter sur ".$name);
$this->name = $name;
}
}
$testLog = new loggerPerso();
$testLog->testLog();
$testLog->logs("message de log");
$voitureA = new voiture();
$voitureA->setName('Tesla'); |
Partager