logger : add stderr support

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2186 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-06-05 13:56:39 +00:00
parent 8f1d5f9076
commit 440eba1415

View File

@@ -141,6 +141,8 @@ class logger
$logsType = $this->logtype;
if (in_array ("display", $logsType))
$this->logdisplay ($msg, $priority);
if (in_array ("stderr", $logsType))
$this->logstderr ($msg, $priority);
if (in_array ("file", $logsType))
$this->logfile ($msg, $priority);
if (in_array ("syslog", $logsType))
@@ -197,6 +199,22 @@ class logger
echo "\n";
}
/** Log $message on stderr with adding date. Add the HTML flags if not in CLI.
@param string $message Message to log
@param integer|null $priority Priority to use */
private function logstderr ($message, $priority)
{
if (php_sapi_name () !== "cli")
file_put_contents("php://stderr", "<tt>");
ini_set ("date.timezone", $this->timezone);
$message = date ("Y/m/d H:i:s")." [".$this->priorities[$priority]."] ".
$message;
file_put_contents("php://stderr", "$message");
if (php_sapi_name () !== "cli")
file_put_contents("php://stderr", "</tt><br/>");
file_put_contents("php://stderr", "\n");
}
/** Log $message on syslog
@param string $message Message to log
@param integer|null $priority Priority to use */