[Piwik-svn] r485 - in trunk/modules: . Log
svnmaster at piwik.org
svnmaster at piwik.org
Tue May 20 00:29:56 CEST 2008
Author: matt
Date: 2008-05-20 00:29:55 +0200 (Tue, 20 May 2008)
New Revision: 485
Modified:
trunk/modules/ArchiveProcessing.php
trunk/modules/Log.php
trunk/modules/Log/APICall.php
trunk/modules/Log/Error.php
trunk/modules/Log/Exception.php
trunk/modules/Log/Message.php
trunk/modules/Piwik.php
Log:
- improving PHP cli error logging
Modified: trunk/modules/ArchiveProcessing.php
===================================================================
--- trunk/modules/ArchiveProcessing.php 2008-05-18 18:19:09 UTC (rev 484)
+++ trunk/modules/ArchiveProcessing.php 2008-05-19 22:29:55 UTC (rev 485)
@@ -590,8 +590,7 @@
$enableBrowserArchivingTriggering = (bool)Zend_Registry::get('config')->General->enable_browser_archiving_triggering;
if($enableBrowserArchivingTriggering == false)
{
- $sapi_type = php_sapi_name();
- if( !in_array(substr($sapi_type, 0, 3), array('cgi', 'cli')))
+ if( !Piwik::isPhpCliMode())
{
$archivingIsDisabled = true;
}
Modified: trunk/modules/Log/APICall.php
===================================================================
--- trunk/modules/Log/APICall.php 2008-05-18 18:19:09 UTC (rev 484)
+++ trunk/modules/Log/APICall.php 2008-05-19 22:29:55 UTC (rev 485)
@@ -57,7 +57,7 @@
* @package Piwik_Log
* @subpackage Piwik_Log_APICall
*/
-class Piwik_Log_Formatter_APICall_ScreenFormatter implements Zend_Log_Formatter_Interface
+class Piwik_Log_Formatter_APICall_ScreenFormatter extends Piwik_Log_Formatter_ScreenFormatter
{
/**
* Formats data into a single line to be written by the writer.
@@ -94,7 +94,7 @@
// $str .= "Returned: ".$this->formatValue($event['returned_value']);
$str .= "\n<br> ";
- return $str;
+ return parent::format($str);
}
private function formatValue( $value )
Modified: trunk/modules/Log/Error.php
===================================================================
--- trunk/modules/Log/Error.php 2008-05-18 18:19:09 UTC (rev 484)
+++ trunk/modules/Log/Error.php 2008-05-19 22:29:55 UTC (rev 485)
@@ -63,7 +63,7 @@
* @package Piwik_Log
* @subpackage Piwik_Log_Error
*/
-class Piwik_Log_Formatter_Error_ScreenFormatter implements Zend_Log_Formatter_Interface
+class Piwik_Log_Formatter_Error_ScreenFormatter extends Piwik_Log_Formatter_ScreenFormatter
{
/**
* Formats data into a single line to be written by the writer.
@@ -111,7 +111,7 @@
$strReturned .= "</div><br><br>";
$strReturned .= "\n</pre></div><br>";
- return $strReturned;
+ return parent::format($strReturned);
}
}
Modified: trunk/modules/Log/Exception.php
===================================================================
--- trunk/modules/Log/Exception.php 2008-05-18 18:19:09 UTC (rev 484)
+++ trunk/modules/Log/Exception.php 2008-05-19 22:29:55 UTC (rev 485)
@@ -1,11 +1,11 @@
<?php
/**
* Piwik - Open source web analytics
- *
+ *
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id$
- *
+ *
* @package Piwik_Log
* @subpackage Piwik_Log_Exception
*/
@@ -14,7 +14,7 @@
/**
* Class used to log an exception event.
* Displays the exception with a user friendly error message, suggests to get support from piwik.org
- *
+ *
* @package Piwik_Log
* @subpackage Piwik_Log_Exception
*/
@@ -28,12 +28,12 @@
$logToDatabaseColumnMapping = null;
$screenFormatter = new Piwik_Log_Formatter_Exception_ScreenFormatter;
$fileFormatter = new Piwik_Log_Formatter_FileFormatter;
-
- parent::__construct($logToFileFilename,
- $fileFormatter,
- $screenFormatter,
- $logToDatabaseTableName,
- $logToDatabaseColumnMapping );
+
+ parent::__construct($logToFileFilename,
+ $fileFormatter,
+ $screenFormatter,
+ $logToDatabaseTableName,
+ $logToDatabaseColumnMapping );
}
function addWriteToScreen()
@@ -43,17 +43,17 @@
$writerScreen->setFormatter( $this->screenFormatter );
$this->addWriter($writerScreen);
}
-
+
public function log($exception)
{
-
+
$event = array();
$event['errno'] = $exception->getCode();
$event['message'] = $exception->getMessage();
$event['errfile'] = $exception->getFile();
$event['errline'] = $exception->getLine();
$event['backtrace'] = $exception->getTraceAsString();
-
+
parent::log($event);
}
}
@@ -61,45 +61,46 @@
/**
* Format an exception event to be displayed on the screen.
- *
+ *
* @package Piwik_Log
* @subpackage Piwik_Log_Exception
*/
-class Piwik_Log_Formatter_Exception_ScreenFormatter implements Zend_Log_Formatter_Interface
+class Piwik_Log_Formatter_Exception_ScreenFormatter extends Piwik_Log_Formatter_ScreenFormatter
{
/**
- * Formats data into a single line to be written by the writer.
- *
- * @param array $event event data
- * @return string formatted line to write to the log
- */
- public function format($event)
- {
+ * Formats data into a single line to be written by the writer.
+ *
+ * @param array $event event data
+ * @return string formatted line to write to the log
+ */
+ public function format($event)
+ {
$errno = $event['errno'] ;
$errstr = $event['message'] ;
$errfile = $event['errfile'] ;
$errline = $event['errline'] ;
$backtrace = $event['backtrace'] ;
-
+
$divId = 'div'.$errline.$errno.rand(1,2000);
-
+
$message = "<b>Uncaught exception</b>: '". $errstr."'";
- $message .= "<br><a onclick=\"if(document.getElementById('$divId').style.display=='none') { document.getElementById('$divId').style.display='inline' } else { document.getElementById('$divId').style.display = 'none' }\" href='#'>More information</a>
- <div style='display:inline' id='$divId'>
- <br> In <b>$errfile</b> on line <b>$errline</b>
- <br> <small>Backtrace:<br><pre >";
+ $message .= "<br><a onclick=\"if(document.getElementById('$divId').style.display=='none') { document.getElementById('$divId').style.display='inline' } else { document.getElementById('$divId').style.display = 'none' }\" href='#'>".
+ "\nMore information</a>".
+ "<div style='display:inline' id='$divId'>".
+ "<br>In <b>$errfile</b> on line <b>$errline</b>".
+ "<br><small>Backtrace:<br><pre>";
$message .= str_replace("\n", "<br>", $backtrace);
$message .= "</pre>";
$message .= "</small></div>";
// without javascript it displays the full error message
- // but with javascript we hide the DIV and onclick we show it
+ // but with javascript we hide the DIV and onclick we show it
$message .= "<script>document.getElementById('$divId').style.display='none';</script>";
-
+
$message .= "<br>You can get help from http://piwik.org (give us the full error message + your PHP and Mysql version)";
- return $message;
- }
+ return parent::format($message);
+ }
}
Modified: trunk/modules/Log/Message.php
===================================================================
--- trunk/modules/Log/Message.php 2008-05-18 18:19:09 UTC (rev 484)
+++ trunk/modules/Log/Message.php 2008-05-19 22:29:55 UTC (rev 485)
@@ -63,12 +63,14 @@
{
if(is_array($event['message']))
{
- return "<pre>".var_export($event['message'], true)."</pre>";
+ $message = "<pre>".var_export($event['message'], true)."</pre>";
}
else
{
- return $event['message'];
+ $message = $event['message'];
}
+
+ return parent::format($message);
}
}
Modified: trunk/modules/Log.php
===================================================================
--- trunk/modules/Log.php 2008-05-18 18:19:09 UTC (rev 484)
+++ trunk/modules/Log.php 2008-05-19 22:29:55 UTC (rev 485)
@@ -142,4 +142,22 @@
}
}
+class Piwik_Log_Formatter_ScreenFormatter implements Zend_Log_Formatter_Interface
+{
+ function format($string)
+ {
+ $string = self::getFormattedString($string);
+ return $string;
+ }
+
+ static public function getFormattedString($string)
+ {
+ if(Piwik::isPhpCliMode())
+ {
+ $string = str_replace(array('<br>','<br />','<br/>'), "\n", $string);
+ $string = strip_tags($string);
+ }
+ return $string;
+ }
+}
Modified: trunk/modules/Piwik.php
===================================================================
--- trunk/modules/Piwik.php 2008-05-18 18:19:09 UTC (rev 484)
+++ trunk/modules/Piwik.php 2008-05-19 22:29:55 UTC (rev 485)
@@ -174,12 +174,12 @@
*/
static public function exitWithErrorMessage( $message )
{
- print("<style> a { color:red } </style>
- <div style='color:red;font-family:Georgia;font-size:120%'>
- <p><img src='themes/default/images/error_medium.png' style='vertical-align:middle; float:left;padding:20 20 20 20'>
- $message
- </p></div>"
- );
+ $output = "<style>a{color:red;}</style>\n".
+ "<div style='color:red;font-family:Georgia;font-size:120%'>".
+ "<p><img src='themes/default/images/error_medium.png' style='vertical-align:middle; float:left;padding:20 20 20 20'>".
+ $message.
+ "</p></div>";
+ print(Piwik_Log_Formatter_ScreenFormatter::getFormattedString($output));
exit;
}
@@ -361,6 +361,11 @@
}
}
+ static public function isPhpCliMode()
+ {
+ return in_array(substr(php_sapi_name(), 0, 3), array('cgi', 'cli'));
+ }
+
static public function isNumeric($value)
{
return !is_array($value) && ereg('^([-]{0,1}[0-9]{1,}[.]{0,1}[0-9]*)$', $value);
More information about the Piwik-svn
mailing list