#include "../exception/exceptions.h"\r
#include "../utility/string.h"\r
#include <ios>\r
+#include <iomanip>\r
#include <string>\r
#include <ostream>\r
\r
\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