Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Cvs P5ee > [svn:p5ee] r104...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 635 of 694
Post > Topic >>

[svn:p5ee] r10425 - p5ee/trunk/App-Context/lib/App

by spadkins@[EMAIL PROTECTED] Dec 13, 2007 at 10:34 AM

Author: spadkins
Date: Thu Dec 13 10:34:16 2007
New Revision: 10425

Modified:
   p5ee/trunk/App-Context/lib/App/Context.pm

Log:
logging changes, introduced log_hi_res and log_elapsed into the options,
and based on them we now include hi res timestamps and elapsed time since
the last log message when the options are enabled

Modified: p5ee/trunk/App-Context/lib/App/Context.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context.pm	(original)
+++ p5ee/trunk/App-Context/lib/App/Context.pm	Thu Dec 13 10:34:16 2007
@[EMAIL PROTECTED]
 -1577,12 +1577,34 @[EMAIL PROTECTED]
 sub _log {
     &App::sub_entry if ($App::trace);
     my $self = shift;
+    my $hi_res = $self->{options}{log_hi_res};
+    my $elapsed = $self->{options}{log_elapsed};
+    my $timestamp;
+    if ($hi_res) {
+        App->use("Time::HiRes");
+        my @[EMAIL PROTECTED]
 = Time::HiRes::gettimeofday();
+        $timestamp = time2str("%Y-%m-%d %H:%M:%S.", $timestuff[0]) .
$timestuff[1]; 
+        if ($elapsed) {
+            my $elapsed =
Time::HiRes::tv_interval($self->{_last_log_elapsed_time}, \@[EMAIL PROTECTED]
);
+            $timestamp .= " " . sprintf("%.6f", $elapsed);
+            $self->{_last_log_elapsed_time} = \@[EMAIL PROTECTED]
        }
+    }
+    else {
+        my $time = time();
+        $timestamp = time2str("%Y-%m-%d %H:%M:%S", $time); 
+        if ($elapsed) {
+            my $elapsed = $time - $self->{_last_log_elapsed_time};
+            $timestamp .= " " . $elapsed;
+            $self->{_last_log_elapsed_time} = $time;
+        }
+    }
     if ($#_ > 0) {
-        my $fmt =  "[$$] " . time2str("%Y-%m-%d %H:%M:%S", time()) . " "
. shift;
+        my $fmt =  "[$$] $timestamp " . shift;
         printf STDERR $fmt, @[EMAIL PROTECTED]
     }
     elsif ($#_ == 0) {
-        print STDERR "[$$] ", time2str("%Y-%m-%d %H:%M:%S", time()), " ",
@[EMAIL PROTECTED]
        print STDERR "[$$] $timestamp ", @[EMAIL PROTECTED]
     }
     &App::sub_exit() if ($App::trace);
 }




 1 Posts in Topic:
[svn:p5ee] r10425 - p5ee/trunk/App-Context/lib/App
spadkins@[EMAIL PROTECTED  2007-12-13 10:34:17 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 0:32:07 CDT 2008.