Index: /trunk/admin/include/image.class.php
===================================================================
--- /trunk/admin/include/image.class.php	(revision 31102)
+++ /trunk/admin/include/image.class.php	(revision 31103)
@@ -622,4 +622,6 @@
   function write($destination_filepath)
   {
+    global $logger;
+
     $this->add_command('interlace', 'line'); // progressive rendering
     // use 4:2:2 chroma subsampling (reduce file size by 20-30% with "almost" no human perception)
@@ -649,11 +651,11 @@
     $dest = pathinfo($destination_filepath);
     $exec .= ' "'.realpath($dest['dirname']).'/'.$dest['basename'].'" 2>&1';
+    $logger->debug($exec, 'i.php');
     @exec($exec, $returnarray);
 
-    if (function_exists('ilog')) ilog($exec);
     if (is_array($returnarray) && (count($returnarray)>0) )
     {
-      if (function_exists('ilog')) ilog('ERROR', $returnarray);
-      foreach($returnarray as $line)
+      $logger->error('', 'i.php', $returnarray);
+      foreach ($returnarray as $line)
         trigger_error($line, E_USER_WARNING);
     }
Index: /trunk/i.php
===================================================================
--- /trunk/i.php	(revision 31102)
+++ /trunk/i.php	(revision 31103)
@@ -615,7 +615,7 @@
 $timing['total'] = time_step($begin);
 
-if ($logger->severity() >= Logger::INFO)
-{
-  $logger->info('perf', 'i.php', array(
+if ($logger->severity() >= Logger::DEBUG)
+{
+  $logger->debug('', 'i.php', array(
     'src_path' => basename($page['src_path']),
     'derivative_path' => basename($page['derivative_path']),
Index: /trunk/include/Logger.class.php
===================================================================
--- /trunk/include/Logger.class.php	(revision 31102)
+++ /trunk/include/Logger.class.php	(revision 31103)
@@ -96,4 +96,5 @@
   private $_fileHandle = null;
 
+
   /**
    * Class constructor.
@@ -106,9 +107,11 @@
     $this->options = array_merge($this->options, $options);
     
-    if (is_string($this->options['severity'])) {
+    if (is_string($this->options['severity']))
+    {
       $this->options['severity'] = self::codeToLevel($this->options['severity']);
     }
 
-    if ($this->options['severity'] === self::OFF) {
+    if ($this->options['severity'] === self::OFF)
+    {
       return;
     }
@@ -116,5 +119,6 @@
     $this->options['directory'] = rtrim($this->options['directory'], '\\/') . DIRECTORY_SEPARATOR;
 
-    if ($this->options['filename'] == null) {
+    if ($this->options['filename'] == null)
+    {
       $this->options['filename'] = 'log_' . date('Y-m-d') . '.txt';
     }
@@ -122,26 +126,40 @@
     $this->options['filePath'] = $this->options['directory'] . $this->options['filename'];
 
-    if (!file_exists($this->options['directory'])) {
-      mkgetdir($this->options['directory'], MKGETDIR_DEFAULT|MKGETDIR_PROTECT_HTACCESS);
-    }
-
-    if (file_exists($this->options['filePath']) && !is_writable($this->options['filePath'])) {
-      $this->_logStatus = self::STATUS_OPEN_FAILED;
-      throw new RuntimeException(self::$_messages['writefail']);
-      return;
-    }
-
-    if (($this->_fileHandle = fopen($this->options['filePath'], 'a'))) {
-      $this->_logStatus = self::STATUS_LOG_OPEN;
-    }
-    else {
-      $this->_logStatus = self::STATUS_OPEN_FAILED;
-      throw new RuntimeException(self::$_messages['openfail']);
-    }
-
-    if ($this->options['archiveDays'] != self::ARCHIVE_NO_PURGE && rand() % 97 == 0) {
+    if ($this->options['archiveDays'] != self::ARCHIVE_NO_PURGE && rand() % 97 == 0)
+    {
       $this->purge();
     }
   }
+  
+  /**
+   * Open the log file if not already oppenned
+   */
+  private function open()
+  {
+    if ($this->status() == self::STATUS_LOG_CLOSED)
+    {
+      if (!file_exists($this->options['directory']))
+      {
+        mkgetdir($this->options['directory'], MKGETDIR_DEFAULT|MKGETDIR_PROTECT_HTACCESS);
+      }
+
+      if (file_exists($this->options['filePath']) && !is_writable($this->options['filePath']))
+      {
+        $this->_logStatus = self::STATUS_OPEN_FAILED;
+        throw new RuntimeException(self::$_messages['writefail']);
+        return;
+      }
+
+      if (($this->_fileHandle = fopen($this->options['filePath'], 'a')) != false)
+      {
+        $this->_logStatus = self::STATUS_LOG_OPEN;
+      }
+      else
+      {
+        $this->_logStatus = self::STATUS_OPEN_FAILED;
+        throw new RuntimeException(self::$_messages['openfail']);
+      }
+    }
+  }
 
   /**
@@ -150,5 +168,6 @@
   public function __destruct()
   {
-    if ($this->_fileHandle) {
+    if ($this->_fileHandle)
+    {
       fclose($this->_fileHandle);
     }
@@ -281,6 +300,8 @@
   public function log($severity, $message, $cat = null, $args = array())
   {
-    if ($this->severity() >= $severity) {
-      if (is_array($cat)) {
+    if ($this->severity() >= $severity)
+    {
+      if (is_array($cat))
+      {
         $args = $cat;
         $cat = null;
@@ -298,6 +319,9 @@
   public function write($line)
   {
-    if ($this->_logStatus == self::STATUS_LOG_OPEN) {
-      if (fwrite($this->_fileHandle, $line) === false) {
+    $this->open();
+    if ($this->status() == self::STATUS_LOG_OPEN)
+    {
+      if (fwrite($this->_fileHandle, $line) === false)
+      {
         throw new RuntimeException(self::$_messages['writefail']);
       }
@@ -308,10 +332,13 @@
    * Purges files matching 'globPattern' older than 'archiveDays'.
    */
-  public function purge() {
+  public function purge()
+  {
     $files = glob($this->options['directory'] . $this->options['globPattern']);
     $limit = time() - $this->options['archiveDays'] * 86400;
 
-    foreach ($files as $file) {
-      if (@filemtime($file) < $limit) {
+    foreach ($files as $file)
+    {
+      if (@filemtime($file) < $limit)
+      {
         @unlink($file);
       }
@@ -329,10 +356,12 @@
   private function formatMessage($level, $message, $cat, $context)
   {
-    if (!empty($context)) {
-      $message .= "\n" . $this->indent($this->contextToString($context));
+    if (!empty($context))
+    {
+      $message.= "\n" . $this->indent($this->contextToString($context));
     }
     $line = "[" . $this->getTimestamp() . "]\t[" . self::levelToCode($level) . "]\t";
-    if ($cat != null) {
-      $line .= "[" . $cat . "]\t";
+    if ($cat != null)
+    {
+      $line.= "[" . $cat . "]\t";
     }
     return $line . $message . "\n";
@@ -350,5 +379,5 @@
   {
     $originalTime = microtime(true);
-    $micro = sprintf("%06d", ($originalTime - floor($originalTime)) * 1000000);
+    $micro = sprintf('%06d', ($originalTime - floor($originalTime)) * 1000000);
     $date = new DateTime(date('Y-m-d H:i:s.'.$micro, $originalTime));
     return $date->format($this->options['dateFormat']);
@@ -364,16 +393,20 @@
   {
     $export = '';
-    foreach ($context as $key => $value) {
-      $export .= "{$key}: ";
-      $export .= preg_replace(array(
+    foreach ($context as $key => $value)
+    {
+      $export.= $key . ': ';
+      $export.= preg_replace(array(
         '/=>\s+([a-zA-Z])/im',
         '/array\(\s+\)/im',
         '/^  |\G  /m'
-      ), array(
+        ),
+        array(
         '=> $1',
         'array()',
         '  '
-      ), str_replace('array (', 'array(', var_export($value, true)));
-      $export .= PHP_EOL;
+        ),
+        str_replace('array (', 'array(', var_export($value, true))
+        );
+      $export.= PHP_EOL;
     }
     return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export));
@@ -389,5 +422,5 @@
   private function indent($string, $indent = '  ')
   {
-    return $indent.str_replace("\n", "\n".$indent, $string);
+    return $indent . str_replace("\n", "\n" . $indent, $string);
   }
 
@@ -400,5 +433,6 @@
   static function levelToCode($level)
   {
-    switch ($level) {
+    switch ($level)
+    {
       case self::EMERGENCY:
         return 'EMERGENCY';
@@ -430,5 +464,6 @@
   static function codeToLevel($code)
   {
-    switch (strtoupper($code)) {
+    switch (strtoupper($code))
+    {
       case 'EMERGENCY':
         return self::EMERGENCY;
