- 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 a6cb06c1f2ac4643a07ff9ce86e67e8310f0ddf4..75537344803be077d19ccc3ff58e0504df0fe8c7 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 d9a78db1e475c5f11c36702ee4a3ce4df447e489..01350a279e7a8fdcb7f33c437135b144e075ffb0 100644 (file)
@@ -120,7 +120,6 @@ namespace zypp
       /** Default ctor: Singleton */
       LogControl()
       {}
-      bool _log_microseconds;
     };
     ///////////////////////////////////////////////////////////////////
 
index c806365c9c98f0b78bcc3b87787c3a5390af10cb..8e0e2c20fba23e94e2bf92779cec92a09bbc803c 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() );
     }