- Implement microseconds logging when ZYPP_PROFILING env variable is
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 10 Oct 2006 14:03:25 +0000 (14:03 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 10 Oct 2006 14:03:25 +0000 (14:03 +0000)
  enabled.

zypp/base/LogControl.cc
zypp/base/LogControl.h
zypp/base/ProfilingFormater.cc

index a6cb06c..7553734 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "zypp/base/Logger.h"
 #include "zypp/base/LogControl.h"
+#include "zypp/base/ProfilingFormater.h"
 #include "zypp/base/String.h"
 #include "zypp/Date.h"
 #include "zypp/PathInfo.h"
@@ -301,6 +302,12 @@ namespace zypp
         {
           if ( getenv("ZYPP_LOGFILE") )
             logfile( getenv("ZYPP_LOGFILE") );
+          
+          if ( getenv("ZYPP_PROFILING") )
+          {
+            shared_ptr<LogControl::LineFormater> formater(new ProfilingFormater);
+            setLineFormater(formater);
+          }
         }
 
       public:
index d9a78db..01350a2 100644 (file)
@@ -120,7 +120,6 @@ namespace zypp
       /** Default ctor: Singleton */
       LogControl()
       {}
-      bool _log_microseconds;
     };
     ///////////////////////////////////////////////////////////////////
 
index c806365..8e0e2c2 100644 (file)
@@ -9,6 +9,9 @@
 /** \file      zypp/base/LogControl.cc
  *
 */
+
+#include <sys/time.h>
+
 #include <iostream>
 #include <fstream>
 #include <string>
@@ -42,14 +45,16 @@ namespace zypp
                                                   int                 line_r,
                                                   const std::string & message_r )
     {
-      static char hostname[1024];
-      static char nohostname[] = "unknown";
-      std::string now( Date::now().form( "%Y-%m-%d %H:%M:%S" ) );
-      return str::form( "%s <%d> %s(%d) [%s] %s(%s):%d %s",
-                        now.c_str(), level_r,
-                        ( gethostname( hostname, 1024 ) ? nohostname : hostname ),
+       struct timeval tp;
+       int rtn;
+       rtn = gettimeofday( &tp, NULL);
+       
+        return str::form( "%i.%i [%d] <%d> %s(%s):%d %s",
+                        tp.tv_sec,
+                        tp.tv_usec,
+                        level_r,
                         getpid(),
-                        group_r.c_str(),
+                        /*group_r.c_str(),*/
                         file_r, func_r, line_r,
                         message_r.c_str() );
     }