From 618a53b3e633835ac8060b95f1466c235b097b0b Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Mon, 31 Mar 2014 08:18:22 +0800 Subject: [PATCH 1/2] Fix bug #2262 --- ext/logger/formatter/firephp.c | 1 + ext/logger/formatter/json.c | 3 ++- ext/logger/formatter/line.c | 1 + ext/logger/formatter/syslog.c | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/logger/formatter/firephp.c b/ext/logger/formatter/firephp.c index fb703b9f66a..e0f1b49ffc9 100644 --- a/ext/logger/formatter/firephp.c +++ b/ext/logger/formatter/firephp.c @@ -146,6 +146,7 @@ PHP_METHOD(Phalcon_Logger_Formatter_Firephp, getTypeString) { * @param string $message * @param int $type * @param int $timestamp + * @param array $context * @return string */ PHP_METHOD(Phalcon_Logger_Formatter_Firephp, format) { diff --git a/ext/logger/formatter/json.c b/ext/logger/formatter/json.c index 377e059983f..55eda77dfbb 100644 --- a/ext/logger/formatter/json.c +++ b/ext/logger/formatter/json.c @@ -60,6 +60,7 @@ PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Json){ * @param string $message * @param int $type * @param int $timestamp + * @param array $context * @return string */ PHP_METHOD(Phalcon_Logger_Formatter_Json, format){ @@ -68,7 +69,7 @@ PHP_METHOD(Phalcon_Logger_Formatter_Json, format){ PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &message, &type, ×tamp, &context); + phalcon_fetch_params(1, 4, 0, &message, &type, ×tamp, &context); if (Z_TYPE_P(context) == IS_ARRAY) { PHALCON_CALL_METHOD(&interpolated, this_ptr, "interpolate", message, context); diff --git a/ext/logger/formatter/line.c b/ext/logger/formatter/line.c index 36b51896c18..71308afb3e8 100644 --- a/ext/logger/formatter/line.c +++ b/ext/logger/formatter/line.c @@ -161,6 +161,7 @@ PHP_METHOD(Phalcon_Logger_Formatter_Line, getDateFormat){ * @param string $message * @param int $type * @param int $timestamp + * @param array $context * @return string */ PHP_METHOD(Phalcon_Logger_Formatter_Line, format){ diff --git a/ext/logger/formatter/syslog.c b/ext/logger/formatter/syslog.c index 0418b8fa6bb..31d74e66baf 100644 --- a/ext/logger/formatter/syslog.c +++ b/ext/logger/formatter/syslog.c @@ -57,6 +57,7 @@ PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Syslog){ * @param string $message * @param int $type * @param int $timestamp + * @param array $context * @return array */ PHP_METHOD(Phalcon_Logger_Formatter_Syslog, format){ From 316c92f9514452677f071907a74ef477735ae65b Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Mon, 31 Mar 2014 08:29:56 +0800 Subject: [PATCH 2/2] Updated --- unit-tests/LoggerTest.php | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 unit-tests/LoggerTest.php diff --git a/unit-tests/LoggerTest.php b/unit-tests/LoggerTest.php new file mode 100644 index 00000000000..19ce92650d4 --- /dev/null +++ b/unit-tests/LoggerTest.php @@ -0,0 +1,55 @@ + | + | Eduar Carvajal | + +------------------------------------------------------------------------+ +*/ + +class LoggerTest extends PHPUnit_Framework_TestCase +{ + public function testFileAdapter() + { + date_default_timezone_set('UTC'); + + $logfile = "unit-tests/logs/file.log"; + + @unlink($logfile); + + $logger = new \Phalcon\Logger\Adapter\File($logfile); + $logger->log('This is a message'); + $logger->log("This is an error", \Phalcon\Logger::ERROR); + $logger->error("This is another error"); + + $lines = file($logfile); + $this->assertEquals(count($lines), 3); + } + + public function testIssues2262() + { + $logfile = "unit-tests/logs/file.log"; + + @unlink($logfile); + + $logger = new \Phalcon\Logger\Adapter\File($logfile); + $logger->setFormatter(new \Phalcon\Logger\Formatter\Json()); + $logger->log('This is a message'); + $logger->log("This is an error", \Phalcon\Logger::ERROR); + $logger->error("This is another error"); + + $lines = file($logfile); + $this->assertEquals(count($lines), 3); + } +}