php__phplib/OSInet/Class_Grapher/Logger.php
Frederic G. MARAND 1e30ed1687 Class_Grapher: accept multiple paths in demo. Logger improvements.
- debugLevel() method replaces debugLevel property.
- PHPUnit tests for Logger.
2012-05-07 22:39:53 +02:00

56 lines
1.2 KiB
PHP

<?php
/**
* @file
* Trivial logger for easier debug.
*/
namespace OSInet\Class_Grapher;
class Logger {
public $fDebugLevel;
public function __construct($debugLevel = LOG_WARNING) {
$this->debugLevel($debugLevel);
}
/**
* Get or Set the current debug level.
*
* @param int $level
* LOG_EMERG to LOG_DEBUG. If NULL, do not set it.
*
* @return
* The value of the debug level before this function was called.
*/
public function debugLevel($level = NULL) {
$ret = $this->fDebugLevel;
if (isset($level)) {
if ($level < LOG_EMERG) {
$level = LOG_EMERG;
}
if ($level > LOG_DEBUG) {
$level = LOG_DEBUG;
}
$this->fDebugLevel = $level;
}
return $ret;
}
/**
* Output a message on STDERR if its relevance is above minimum level.
*
* @param string $message
* @param int $level
* Defined in RFC 3164, section 4.1.1 "Severity". But compare with Drupal 7
* WATCHDOG_* constants in includes/bootstrap.inc for an explanation about
* syslog constants in PHP.
*/
public function debug($message = "\n", $level = LOG_INFO) {
if ($level <= $this->fDebugLevel) {
fputs(STDERR, $message);
fflush(STDERR);
}
}
}