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.

malthoff
 
JohntheFish replied on at Permalink Reply
JohntheFish
I experimented to see if if I could get a log entry by adding to a theme:
<?php Log::addEntry('Test the log from theme');?>
and ended up with no entry in the log
JohntheFish replied on at Permalink Reply
JohntheFish
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.
malthoff replied on at Permalink Reply
malthoff
Hey woah. Thank you for further investigating. I'll try it that way too!
iconicschema replied on at Permalink Reply
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.

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.