We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

About Phalcon\Logger\Adapter\File class, Can not write data

I encountered a problem, in use Phalcon\Logger\Adapter\File class.

About function log,Its third argument is not written。next my code,

$logger = new \Phalcon\Logger\Adapter\File($this->_logs_file);
$logger->log($message, \Phalcon\Logger::DEBUG,  array(11,11,1,1));
$logger->debug("This is another error",array('222','22222'));
$logger->close();

but $content doesn't Writed to file. next is my log

[Thu, 09 Jul 15 10:33:10 +0200][WARNING] 1
[Thu, 09 Jul 15 10:33:10 +0200][DEBUG] This is another error
[Thu, 09 Jul 15 10:33:10 +0200][WARNING] 1
[Thu, 09 Jul 15 10:33:10 +0200][DEBUG] This is another error
[Thu, 09 Jul 15 10:33:11 +0200][WARNING] 1
[Thu, 09 Jul 15 10:33:11 +0200][DEBUG] This is another error
[Thu, 09 Jul 15 10:33:11 +0200][WARNING] 1
[Thu, 09 Jul 15 10:33:11 +0200][DEBUG] This is another error

Who knows why it???



4.0k
Accepted
answer

https://github.com/phalcon/cphalcon/blob/2.0.x/phalcon/logger/formatter.zep#L80

Example:

$logger = new \Phalcon\Logger\Adapter\File($this->_logs_file);
$message = "Context1 = {0}, Context2 = {1}, Context3 = {2}, Context4 = {3} ";
$logger->log($message, \Phalcon\Logger::DEBUG,  array(11,11,1,1));
$logger->debug("This is another error: {0} -> {1}",array('222','22222'));
$logger->debug("Hello {name}, Error {error}",array('name' => 'Jon', 'error' => 'Fatal error foo'));
$logger->close();

Output:

[Thu, 09 Jul 15 12:37:50 +0300][DEBUG] Context1 = 11, Context2 = 11, Context3 = 1, Context4 = 1 
[Thu, 09 Jul 15 12:37:50 +0300][DEBUG] This is another error: 222 -> 22222
[Thu, 09 Jul 15 12:37:50 +0300][DEBUG] Hello Jon, Error Fatal error foo

Thank you. I always thought this parameter is written directly to the

https://github.com/phalcon/cphalcon/blob/2.0.x/phalcon/logger/formatter.zep#L80

Example:

$logger = new \Phalcon\Logger\Adapter\File($this->_logs_file);
$message = "Context1 = {0}, Context2 = {1}, Context3 = {2}, Context4 = {3} ";
$logger->log($message, \Phalcon\Logger::DEBUG,  array(11,11,1,1));
$logger->debug("This is another error: {0} -> {1}",array('222','22222'));
$logger->debug("Hello {name}, Error {error}",array('name' => 'Jon', 'error' => 'Fatal error foo'));
$logger->close();

Output:

[Thu, 09 Jul 15 12:37:50 +0300][DEBUG] Context1 = 11, Context2 = 11, Context3 = 1, Context4 = 1 
[Thu, 09 Jul 15 12:37:50 +0300][DEBUG] This is another error: 222 -> 22222
[Thu, 09 Jul 15 12:37:50 +0300][DEBUG] Hello Jon, Error Fatal error foo