[Box Backup-commit] COMMIT r2001 - box/trunk/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sat Dec 15 20:03:50 GMT 2007


Author: chris
Date: 2007-12-15 20:03:50 +0000 (Sat, 15 Dec 2007)
New Revision: 2001

Modified:
   box/trunk/lib/common/Logging.cpp
   box/trunk/lib/common/Logging.h
Log:
Allow logging with microsecond timestamps.


Modified: box/trunk/lib/common/Logging.cpp
===================================================================
--- box/trunk/lib/common/Logging.cpp	2007-12-15 17:04:24 UTC (rev 2000)
+++ box/trunk/lib/common/Logging.cpp	2007-12-15 20:03:50 UTC (rev 2001)
@@ -20,6 +20,8 @@
 
 #include <iomanip>
 
+#include "BoxTime.h"
+
 bool Logging::sLogToSyslog  = false;
 bool Logging::sLogToConsole = false;
 bool Logging::sContextSet   = false;
@@ -178,7 +180,8 @@
 }
 
 bool Console::sShowTime = false;
-bool Console::sShowTag  = false;
+bool Console::sShowTimeMicros = false;
+bool Console::sShowTag = false;
 std::string Console::sTag;
 
 void Console::SetTag(const std::string& rTag)
@@ -192,6 +195,11 @@
 	sShowTime = enabled;
 }
 
+void Console::SetShowTimeMicros(bool enabled)
+{
+	sShowTimeMicros = enabled;
+}
+
 bool Console::Log(Log::Level level, const std::string& rFile, 
 	int line, std::string& rMessage)
 {
@@ -211,25 +219,31 @@
 
 	if (sShowTime)
 	{
-		struct tm time_now, *tm_ptr = &time_now;
-		time_t time_t_now = time(NULL);
+		box_time_t time_now = GetCurrentBoxTime();
+		time_t seconds = BoxTimeToSeconds(time_now);
+		int micros = BoxTimeToMicroSeconds(time_now) % MICRO_SEC_IN_SEC;
 
-		if (time_t_now == ((time_t)-1))
-		{
-			msg += strerror(errno);
-			msg += " ";
-		}
+		struct tm tm_now, *tm_ptr = &tm_now;
+
 		#ifdef WIN32
-			else if ((tm_ptr = localtime(&time_t_now)) != NULL)
+			if ((tm_ptr = localtime(&seconds)) != NULL)
 		#else
-			else if (localtime_r(&time_t_now, &time_now) != NULL)
+			if (localtime_r(&seconds, &tm_now) != NULL)
 		#endif
 		{
 			std::ostringstream buf;
+
 			buf << std::setfill('0') <<
 				std::setw(2) << tm_ptr->tm_hour << ":" << 
 				std::setw(2) << tm_ptr->tm_min  << ":" <<
-				std::setw(2) << tm_ptr->tm_sec  << " ";
+				std::setw(2) << tm_ptr->tm_sec;
+
+			if (sShowTimeMicros)
+			{
+				buf << "." << std::setw(6) << micros;
+			}
+
+			buf << " ";
 			msg += buf.str();
 		}
 		else

Modified: box/trunk/lib/common/Logging.h
===================================================================
--- box/trunk/lib/common/Logging.h	2007-12-15 17:04:24 UTC (rev 2000)
+++ box/trunk/lib/common/Logging.h	2007-12-15 20:03:50 UTC (rev 2001)
@@ -118,6 +118,7 @@
 {
 	private:
 	static bool sShowTime;
+	static bool sShowTimeMicros;
 	static bool sShowTag;
 	static std::string sTag;
 
@@ -129,6 +130,7 @@
 
 	static void SetTag(const std::string& rTag);
 	static void SetShowTime(bool enabled);
+	static void SetShowTimeMicros(bool enabled);
 };
 
 // --------------------------------------------------------------------------




More information about the Boxbackup-commit mailing list