Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.3.0 Phalcon\Logger\Formatter\Json::format Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters' #2262

Closed
chameleonbr opened this issue Mar 30, 2014 · 1 comment

Comments

@chameleonbr
Copy link

Phalcon\Logger\Formatter\Json Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters'.
Code example:

$log = new \Phalcon\Logger\Adapter\File("test.log");
$log->setFormatter(new  Phalcon\Logger\Formatter\Json());
$log->info('test');

<bountysource-plugin>

---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1896253-1-3-0-phalcon-logger-formatter-json-format-uncaught-exception-badmethodcallexception-with-message-wrong-number-of-parameters?utm_campaign=plugin&utm_content=tracker%2F50707&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F50707&utm_medium=issues&utm_source=github).
</bountysource-plugin>
@chameleonbr
Copy link
Author

Workaround Class

namespace App\Logger\Formatter;

use Phalcon\Logger as Logger;

class Json extends Logger\Formatter implements Logger\FormatterInterface
{
    protected $date_format = null;
    public function __construct($options = array())
    {
        $default = array('date_format'=>null);
        $options = array_merge($default,$options);
        $this->setDateFormat($options['date_format']);
    }
    public function format ($message, $type, $timestamp, $context = array())
    {
        $timestamp = $this->getFormattedDate($timestamp);
        $type = $this->getTypeString($type);
        return json_encode(compact('timestamp','type','message'));
    }

    protected function setDateFormat($format)
    {
        $this->date_format = $format;
        return $this;
    }
    protected function getDateFormat()
    {
        return $this->date_format;
    }

    protected function getFormattedDate($timestamp = null){
        if($this->date_format !== null){
            return date($this->date_format,$timestamp);
        } else {
            return $timestamp;
        }
    }
}

@chameleonbr chameleonbr changed the title 1.3.0 Phalcon\Logger\Formatter\Json Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters' 1.3.0 Phalcon\Logger\Formatter\Json::format Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters' Mar 30, 2014
phalcon pushed a commit that referenced this issue Mar 31, 2014
Fix bug #2262 `\Phalcon\Logger\Formatter\Json` Wrong number of parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants