X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=php%2Fphpxmlrpc%2Fsrc%2FHelper%2FLogger.php;fp=php%2Fphpxmlrpc%2Fsrc%2FHelper%2FLogger.php;h=bee7b08f00b4283567451950533e3aa6bfd70938;hb=c379c0fff5edc592cc5d5d647c7fadb91317db87;hp=77e0e149aaafd537af9cc7806a5935597007d9c9;hpb=ae8b10f8363f7a1df02e77cbd820904c4ded10b8;p=plcapi.git diff --git a/php/phpxmlrpc/src/Helper/Logger.php b/php/phpxmlrpc/src/Helper/Logger.php index 77e0e14..bee7b08 100644 --- a/php/phpxmlrpc/src/Helper/Logger.php +++ b/php/phpxmlrpc/src/Helper/Logger.php @@ -2,12 +2,16 @@ namespace PhpXmlRpc\Helper; +/** + * @todo implement an interface + * @todo make constructor private to force users to go through `instance()` ? + */ class Logger { protected static $instance = null; /** - * This class is singleton, so that later we can move to DI patterns. + * This class can be used as singleton, so that later we can move to DI patterns. * * @return Logger */ @@ -28,7 +32,7 @@ class Logger * @param string $message * @param string $encoding */ - public function debugMessage($message, $encoding=null) + public function debugMessage($message, $encoding = null) { // US-ASCII is a warning for PHP and a fatal for HHVM if ($encoding == 'US-ASCII') { @@ -36,7 +40,14 @@ class Logger } if (PHP_SAPI != 'cli') { - $flags = ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE; + $flags = ENT_COMPAT; + // avoid warnings on php < 5.4... + if (defined('ENT_HTML401')) { + $flags = $flags | ENT_HTML401; + } + if (defined('ENT_SUBSTITUTE')) { + $flags = $flags | ENT_SUBSTITUTE; + } if ($encoding != null) { print "
\n".htmlentities($message, $flags, $encoding)."\n
"; } else { @@ -49,4 +60,13 @@ class Logger // let the user see this now in case there's a time out later... flush(); } + + /** + * Writes a message to the error log + * @param string $message + */ + public function errorLog($message) + { + error_log($message); + } }