Logging does not work in block controller
Permalink
Update: My controller wasn't syntax error free and that error died silently. this thread can be killed by authority :)
i tried: Log::addEntry('bid: '.$this->bID); but nothing appeared in the log files.
i tried: Log::addEntry('bid: '.$this->bID); but nothing appeared in the log files.
Upon further experimenting, I can get a log message to show if I use the long way:
$l = new Log('My Group', true);
$l->write('Test log with close');
$l->close();
Reading the code for Log::addEntry, I suspect that the problem may be that it doesn't $l->close(), so the entry never gets output to the database. To test this I have hacked the Log::addEntry function to now be ...
public static function addEntry($message, $namespace = null) {
$l = new Log($namespace);
$l->write($message);
$l->close();
}
... and it appears to work. So now all I need is some confirmation from the experts that this is a good hack and won't cause adverse side effects elsewhere.
$l = new Log('My Group', true);
$l->write('Test log with close');
$l->close();
Reading the code for Log::addEntry, I suspect that the problem may be that it doesn't $l->close(), so the entry never gets output to the database. To test this I have hacked the Log::addEntry function to now be ...
public static function addEntry($message, $namespace = null) {
$l = new Log($namespace);
$l->write($message);
$l->close();
}
... and it appears to work. So now all I need is some confirmation from the experts that this is a good hack and won't cause adverse side effects elsewhere.
Hey woah. Thank you for further investigating. I'll try it that way too!
Hello John,
I am having a problem with logging during an application event and I came across your post. I know it is a little dated, but I thought it might be helpful to have this tidbit of information.
The Log::addEntry function sets 'session' to false. If you take a look at the write() function it checks if session is false and calls close() after the first write.
It should not be necessary to call close() on addEntry() as the write function already does that.
I am having a problem with logging during an application event and I came across your post. I know it is a little dated, but I thought it might be helpful to have this tidbit of information.
The Log::addEntry function sets 'session' to false. If you take a look at the write() function it checks if session is false and calls close() after the first write.
public function write($message) { $this->sessionText .= $message . "\n"; if (!$this->session) { $this->close(); } }
It should not be necessary to call close() on addEntry() as the write function already does that.
<?php Log::addEntry('Test the log from theme');?>
and ended up with no entry in the log