]> git.sesse.net Git - casparcg/commitdiff
Changed date format in logging and added millisecond
authorhellgore <hellgore@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 6 Feb 2013 12:45:47 +0000 (12:45 +0000)
committerhellgore <hellgore@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Wed, 6 Feb 2013 12:45:47 +0000 (12:45 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/trunk@3734 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

common/log/log.cpp

index 0c7620831c8e837d3f73d59ebbdb2a9394220da5..5051d097f7a7b0a06445b9dfdd3ae9fae912c31c 100644 (file)
@@ -31,6 +31,7 @@
 #include "../exception/exceptions.h"\r
 #include "../utility/string.h"\r
 #include <ios>\r
+#include <iomanip>\r
 #include <string>\r
 #include <ostream>\r
 \r
@@ -69,18 +70,35 @@ namespace caspar { namespace log {
 \r
 using namespace boost;\r
 \r
+void append_timestamp(std::wostream& stream)\r
+{\r
+       auto timestamp = boost::posix_time::microsec_clock::local_time();\r
+       auto date = timestamp.date();\r
+       auto time = timestamp.time_of_day();\r
+       auto milliseconds = time.fractional_seconds() / 1000; // microseconds to milliseconds\r
+\r
+       std::wstringstream buffer;\r
+\r
+       buffer\r
+               << std::setfill(L'0')\r
+               << L"["\r
+               << std::setw(4) << date.year() << L"-" << std::setw(2) << date.month().as_number() << "-" << std::setw(2) << date.day().as_number()\r
+               << L" "\r
+               << std::setw(2) << time.hours() << L":" << std::setw(2) << time.minutes() << L":" << std::setw(2) << time.seconds()\r
+               << L"."\r
+               << std::setw(3) << milliseconds\r
+               << L"] ";\r
+\r
+       stream << buffer.str();\r
+}\r
+\r
 void my_formatter(bool print_all_characters, std::wostream& strm, boost::log::basic_record<wchar_t> const& rec)\r
 {\r
     namespace lambda = boost::lambda;\r
        \r
        #pragma warning(disable : 4996)\r
-       time_t rawtime;\r
-       struct tm* timeinfo;\r
-       time(&rawtime );\r
-       timeinfo = localtime ( &rawtime );\r
-       char buffer [80];\r
-       strftime (buffer,80, "%c", timeinfo);\r
-       strm << L"[" << buffer << L"] ";\r
+\r
+       append_timestamp(strm);\r
                \r
     boost::log::attributes::current_thread_id::held_type thread_id;\r
     if(boost::log::extract<boost::log::attributes::current_thread_id::held_type>(L"ThreadID", rec.attribute_values(), lambda::var(thread_id) = lambda::_1))\r