Skip to content

Commit

Permalink
Merge pull request #2263 from dreamsxin/2262
Browse files Browse the repository at this point in the history
Fix bug #2262 `\Phalcon\Logger\Formatter\Json` Wrong number of parameters
  • Loading branch information
Phalcon committed Mar 31, 2014
2 parents 75276a4 + 316c92f commit f6566e8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions ext/logger/formatter/firephp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion ext/logger/formatter/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -68,7 +69,7 @@ PHP_METHOD(Phalcon_Logger_Formatter_Json, format){

PHALCON_MM_GROW();

phalcon_fetch_params(1, 3, 0, &message, &type, &timestamp, &context);
phalcon_fetch_params(1, 4, 0, &message, &type, &timestamp, &context);

if (Z_TYPE_P(context) == IS_ARRAY) {
PHALCON_CALL_METHOD(&interpolated, this_ptr, "interpolate", message, context);
Expand Down
1 change: 1 addition & 0 deletions ext/logger/formatter/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
1 change: 1 addition & 0 deletions ext/logger/formatter/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
55 changes: 55 additions & 0 deletions unit-tests/LoggerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
+------------------------------------------------------------------------+
*/

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);
}
}

0 comments on commit f6566e8

Please sign in to comment.