/**
  * Writes a line to the log, if the log level is high enough
  *
  * @param int|bool $level The log level (_JP_LOG_XX constants). Use FALSE to pause logging, TRUE to resume logging
  * @param string $message The message to write to the log
  */
 function WriteLog($level, $message)
 {
     static $configuredLoglevel;
     static $site_root;
     if (empty($site_root)) {
         if (!class_exists('JoomlapackHelperUtils')) {
             jpimport('helpers.utils', true);
         }
         $site_root = JoomlapackHelperUtils::TranslateWinPath(JPATH_SITE);
     }
     if (empty($configuredLoglevel) or $level === true) {
         // Load the registry
         if (!class_exists('JoomlapackModelRegistry')) {
             jpimport('models.registry', true);
         }
         $registry =& JoomlapackModelRegistry::getInstance();
         // Fetch log level
         $configuredLoglevel = $registry->get('logLevel');
     }
     if ($level === false) {
         // Pause logging
         $configuredLogLevel = false;
         return;
     }
     // Catch paused logging
     if ($configuredLoglevel === false) {
         return;
     }
     if ($configuredLoglevel >= $level && $configuredLoglevel != 0) {
         $logName = JoomlapackLogger::logName();
         $message = str_replace(JPATH_SITE, "<root>", $message);
         $message = str_replace($site_root, "<root>", $message);
         // Fix 2.4 - Also replace the translated path on Windows machines
         $message = str_replace("\n", ' \\n ', $message);
         // Fix 1.1.1 - Handle (error) messages containing newlines (by nicholas)
         switch ($level) {
             case _JP_LOG_ERROR:
                 $string = "ERROR   |";
                 break;
             case _JP_LOG_WARNING:
                 $string = "WARNING |";
                 break;
             case _JP_LOG_INFO:
                 $string = "INFO    |";
                 break;
             default:
                 $string = "DEBUG   |";
                 break;
         }
         $string .= @strftime("%y%m%d %T") . "|{$message}\r\n";
         $fp = @fopen($logName, "at");
         if (!($fp === FALSE)) {
             @fwrite($fp, $string);
             @fclose($fp);
         }
     }
 }
Exemple #2
0
 /**
  * Parses the log file and outputs formatted HTML to the standard output
  */
 function VisualizeLogDirect()
 {
     $logName = JoomlapackLogger::logName();
     if (!file_exists($logName)) {
         return false;
     }
     //joostina pach
     $fp = fopen($logName, "rt");
     if ($fp === FALSE) {
         return false;
     }
     while (!feof($fp)) {
         $line = fgets($fp);
         if (!$line) {
             return;
         }
         $exploded = explode("|", $line, 3);
         unset($line);
         switch (trim($exploded[0])) {
             case "ERROR":
                 $fmtString = "<span style=\"color: red; font-weight: bold;\">[";
                 break;
             case "WARNING":
                 $fmtString = "<span style=\"color: #D8AD00; font-weight: bold;\">[";
                 break;
             case "INFO":
                 $fmtString = "<span style=\"color: black;\">[";
                 break;
             case "DEBUG":
                 $fmtString = "<span style=\"color: #666666; font-size: small;\">[";
                 break;
             default:
                 $fmtString = "<span style=\"font-size: small;\">[";
                 break;
         }
         $fmtString .= $exploded[1] . "] " . htmlspecialchars($exploded[2]) . "</span><br/>\n";
         unset($exploded);
         echo $fmtString;
         unset($fmtString);
         ob_flush();
     }
     //ob_flush();
 }
 /**
  * Writes a line to the log, if the log level is high enough
  *
  * @param integer $level The log level (_JP_LOG_XX constants)
  * @param string $message The message to write to the log
  */
 function WriteLog($level, $message)
 {
     // Load the registry
     if (!class_exists('JoomlapackModelRegistry')) {
         jpimport('models.registry', true);
     }
     $registry =& JoomlapackModelRegistry::getInstance();
     // Fetch log level
     $configuredLoglevel = $registry->get('logLevel');
     if ($configuredLoglevel >= $level && $configuredLoglevel != 0) {
         $logName = JoomlapackLogger::logName();
         $message = str_replace(JPATH_SITE, "<root>", $message);
         $message = str_replace("\n", ' \\n ', $message);
         // Fix 1.1.1 - Handle (error) messages containing newlines (by nicholas)
         switch ($level) {
             case _JP_LOG_ERROR:
                 $string = "ERROR   |";
                 break;
             case _JP_LOG_WARNING:
                 $string = "WARNING |";
                 break;
             case _JP_LOG_INFO:
                 $string = "INFO    |";
                 break;
             default:
                 $string = "DEBUG   |";
                 break;
         }
         $string .= @strftime("%y%m%d %T") . "|{$message}\r\n";
         $fp = @fopen($logName, "at");
         if (!($fp === FALSE)) {
             @fwrite($fp, $string);
             @fclose($fp);
         }
     }
 }