unit test for Tlog. Cover all output method (trace to fatal)
This commit is contained in:
45
core/lib/Thelia/Log/Destination/TlogDestinationNull.php
Normal file
45
core/lib/Thelia/Log/Destination/TlogDestinationNull.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationNull extends AbstractTlogDestination {
|
||||
|
||||
public function get_titre() {
|
||||
return "Trou noir";
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
return "Cette destination ne provoque aucune sortie";
|
||||
}
|
||||
|
||||
public function ajouter($string) {
|
||||
// Rien
|
||||
}
|
||||
|
||||
public function ecrire(&$res) {
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
50
core/lib/Thelia/Log/Destination/TlogDestinationText.php
Normal file
50
core/lib/Thelia/Log/Destination/TlogDestinationText.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
|
||||
class TlogDestinationText extends AbstractTlogDestination {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function get_titre() {
|
||||
return "Affichage direct dans la page, en texte brut";
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
return "Permet d'afficher les logs directement dans la page resultat, au format texte brut.";
|
||||
}
|
||||
|
||||
public function ajouter($texte) {
|
||||
echo $texte."\n";
|
||||
}
|
||||
|
||||
public function ecrire(&$res) {
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class Tlog Implements TlogInterface
|
||||
|
||||
// default values
|
||||
const DEFAULT_LEVEL = self::DEBUG;
|
||||
const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationFile";
|
||||
const DEFAUT_DESTINATIONS = "Thelia\Log\Destination\TlogDestinationNull";
|
||||
const DEFAUT_PREFIXE = "#NUM: #NIVEAU [#FICHIER:#FONCTION()] {#LIGNE} #DATE #HEURE: ";
|
||||
const DEFAUT_FILES = "*";
|
||||
const DEFAUT_IP = "";
|
||||
@@ -97,7 +97,7 @@ class Tlog Implements TlogInterface
|
||||
// if (self::$instance == false) {
|
||||
// self::$instance = new Tlog();
|
||||
//
|
||||
// // On doit placer les initialisations à ce niveau pour pouvoir
|
||||
// // On doit placer les initialisations à ce level pour pouvoir
|
||||
// // utiliser la classe Tlog dans les classes de base (Cnx, BaseObj, etc.)
|
||||
// // Les placer dans le constructeur provoquerait une boucle
|
||||
// self::$instance->init();
|
||||
@@ -111,7 +111,7 @@ class Tlog Implements TlogInterface
|
||||
|
||||
$level = $config->read(self::VAR_LEVEL, self::DEFAULT_LEVEL);
|
||||
|
||||
$this->set_niveau($level);
|
||||
$this->set_level($level);
|
||||
|
||||
$this->dir_destinations = array(
|
||||
__DIR__.'/Destination'
|
||||
@@ -141,8 +141,8 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function set_niveau($level) {
|
||||
$this->niveau = $level;
|
||||
public function set_level($level) {
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
public function set_prefixe($prefixe) {
|
||||
@@ -157,7 +157,7 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
public function set_ip($ips) {
|
||||
if (! empty($ips) && ! in_array($_SERVER['REMOTE_ADDR'], explode(";", $ips))) $this->niveau = self::MUET;
|
||||
if (! empty($ips) && ! in_array($_SERVER['REMOTE_ADDR'], explode(";", $ips))) $this->level = self::MUET;
|
||||
}
|
||||
|
||||
public function set_show_redirect($bool) {
|
||||
@@ -186,7 +186,7 @@ class Tlog Implements TlogInterface
|
||||
// ---------------------------
|
||||
|
||||
public function trace() {
|
||||
if ($this->niveau > self::TRACE)
|
||||
if ($this->level > self::TRACE)
|
||||
return;
|
||||
|
||||
$args = func_get_args();
|
||||
@@ -195,7 +195,7 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
public function debug() {
|
||||
if ($this->niveau > self::DEBUG)
|
||||
if ($this->level > self::DEBUG)
|
||||
return;
|
||||
|
||||
$args = func_get_args();
|
||||
@@ -204,7 +204,7 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
public function info() {
|
||||
if ($this->niveau > self::INFO)
|
||||
if ($this->level > self::INFO)
|
||||
return;
|
||||
|
||||
$args = func_get_args();
|
||||
@@ -213,7 +213,7 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
public function warning() {
|
||||
if (Tlog::instance()->niveau > self::WARNING)
|
||||
if ($this->level > self::WARNING)
|
||||
return;
|
||||
|
||||
$args = func_get_args();
|
||||
@@ -222,7 +222,7 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
public function error() {
|
||||
if ($this->niveau > self::ERROR)
|
||||
if ($this->level > self::ERROR)
|
||||
return;
|
||||
|
||||
$args = func_get_args();
|
||||
@@ -231,7 +231,7 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
public function fatal() {
|
||||
if ($this->niveau > self::FATAL)
|
||||
if ($this->level > self::FATAL)
|
||||
return;
|
||||
|
||||
$args = func_get_args();
|
||||
@@ -253,7 +253,7 @@ class Tlog Implements TlogInterface
|
||||
self::$ecrire_effectue = true;
|
||||
|
||||
// Muet ? On ne fait rien
|
||||
if ($this->niveau == self::MUET) return;
|
||||
if ($this->level == self::MUET) return;
|
||||
|
||||
foreach($this->destinations as $dest) {
|
||||
$dest->ecrire($res);
|
||||
@@ -274,7 +274,7 @@ class Tlog Implements TlogInterface
|
||||
|
||||
public function afficher_redirections($url) {
|
||||
|
||||
if ($this->niveau != self::MUET && $this->show_redirect) {
|
||||
if ($this->level != self::MUET && $this->show_redirect) {
|
||||
echo "
|
||||
<html>
|
||||
<head><title>Redirection...</title></head>
|
||||
@@ -292,10 +292,10 @@ class Tlog Implements TlogInterface
|
||||
}
|
||||
|
||||
// Permet de déterminer si la trace est active, en prenant en compte
|
||||
// le niveau et le filtrage par fichier
|
||||
// le level et le filtrage par fichier
|
||||
public function active($level) {
|
||||
|
||||
if ($this->niveau <= $level) {
|
||||
if ($this->level <= $level) {
|
||||
|
||||
$origine = $this->trouver_origine();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user