Author: ihabunek
Date: Sat Sep 1 10:06:29 2012
New Revision: 1379731
URL: http://svn.apache.org/viewvc?rev=1379731&view=rev
Log:
LoggerLoggingEvent: Replaced getTime() with getRelativeTime().
The new method, apart from having a better descriptive name, does not perform
unnecessary number formatting, and multiplication by 1000 which getTime() does
so it's faster. Marked getTime() as deprecated.
Modified:
logging/log4php/trunk/src/main/php/LoggerLoggingEvent.php
logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php
logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterRelative.php
logging/log4php/trunk/src/test/php/layouts/LoggerLayoutHtmlTest.php
Modified: logging/log4php/trunk/src/main/php/LoggerLoggingEvent.php
URL:
http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/LoggerLoggingEvent.php?rev=1379731&r1=1379730&r2=1379731&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/LoggerLoggingEvent.php (original)
+++ logging/log4php/trunk/src/main/php/LoggerLoggingEvent.php Sat Sep 1
10:06:29 2012
@@ -305,8 +305,23 @@ class LoggerLoggingEvent {
}
/**
- * Calculates the time of this event.
- * @return the time after event starttime when this event has occured
+ * Returns the time in seconds passed from the beginning of execution
to
+ * the time the event was constructed.
+ *
+ * @return float Seconds with microseconds in decimals.
+ */
+ public function getRelativeTime() {
+ return $this->timeStamp - self::$startTime;
+ }
+
+ /**
+ * Returns the time in milliseconds passed from the beginning of
execution
+ * to the time the event was constructed.
+ *
+ * @deprecated This method has been replaced by getRelativeTime which
+ * does not perform unneccesary multiplication and
formatting.
+ *
+ * @return integer
*/
public function getTime() {
$eventTime = $this->getTimeStamp();
Modified: logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php
URL:
http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php?rev=1379731&r1=1379730&r2=1379731&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php (original)
+++ logging/log4php/trunk/src/main/php/layouts/LoggerLayoutHtml.php Sat Sep 1
10:06:29 2012
@@ -122,7 +122,7 @@ class LoggerLayoutHtml extends LoggerLay
$sbuf = PHP_EOL . "<tr>" . PHP_EOL;
$sbuf .= "<td>";
- $sbuf .= $event->getTime();
+ $sbuf .= round(1000 * $event->getRelativeTime());
$sbuf .= "</td>" . PHP_EOL;
$sbuf .= "<td title=\"" . $event->getThreadName() . "
thread\">";
Modified:
logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterRelative.php
URL:
http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterRelative.php?rev=1379731&r1=1379730&r2=1379731&view=diff
==============================================================================
---
logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterRelative.php
(original)
+++
logging/log4php/trunk/src/main/php/pattern/LoggerPatternConverterRelative.php
Sat Sep 1 10:06:29 2012
@@ -30,7 +30,7 @@
class LoggerPatternConverterRelative extends LoggerPatternConverter {
public function convert(LoggerLoggingEvent $event) {
- $ts = $event->getTimeStamp() - $event->getStartTime();
+ $ts = $event->getRelativeTime();
return number_format($ts, 4);
}
}
Modified: logging/log4php/trunk/src/test/php/layouts/LoggerLayoutHtmlTest.php
URL:
http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/layouts/LoggerLayoutHtmlTest.php?rev=1379731&r1=1379730&r2=1379731&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/layouts/LoggerLayoutHtmlTest.php
(original)
+++ logging/log4php/trunk/src/test/php/layouts/LoggerLayoutHtmlTest.php Sat Sep
1 10:06:29 2012
@@ -35,7 +35,7 @@ class LoggerLayoutHtmlTest extends PHPUn
$v = $layout->format($event);
$e = PHP_EOL."<tr>".PHP_EOL.
- "<td>".$event->getTime()."</td>".PHP_EOL.
+
"<td>".round(1000*$event->getRelativeTime())."</td>".PHP_EOL.
"<td title=\"".$event->getThreadName()."
thread\">".$event->getThreadName()."</td>".PHP_EOL.
"<td title=\"Level\">ERROR</td>".PHP_EOL.
"<td title=\"TEST category\">TEST</td>".PHP_EOL.
@@ -52,7 +52,7 @@ class LoggerLayoutHtmlTest extends PHPUn
$v = $layout->format($event);
$e = PHP_EOL."<tr>".PHP_EOL.
- "<td>".$event->getTime()."</td>".PHP_EOL.
+
"<td>".round(1000*$event->getRelativeTime())."</td>".PHP_EOL.
"<td title=\"".$event->getThreadName()."
thread\">".$event->getThreadName()."</td>".PHP_EOL.
"<td title=\"Level\"><font
color=\"#993300\"><strong>WARN</strong></font></td>".PHP_EOL.
"<td title=\"TEST category\">TEST</td>".PHP_EOL.