From 3d29a5de52b21c7e010323e8a564ac4c1f67fc84 Mon Sep 17 00:00:00 2001 From: zilmar Date: Wed, 13 Jan 2016 06:02:18 +1100 Subject: [PATCH] [Projet64] Make Trace.cpp more linux friendly --- Source/Common/Trace.cpp | 17 +++++++++++++++-- Source/Common/Trace.h | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Source/Common/Trace.cpp b/Source/Common/Trace.cpp index a57c08af5..72a072c86 100644 --- a/Source/Common/Trace.cpp +++ b/Source/Common/Trace.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include typedef std::map ModuleNameMap; @@ -192,9 +191,23 @@ void CTraceFileLog::Write(uint32_t module, uint8_t severity, const char * /*file { if (!m_hLogFile.IsOpen()) { return; } - SYSTEMTIME sysTime; +#ifdef _WIN32 + SYSTEMTIME sysTime; ::GetLocalTime(&sysTime); stdstr_f timestamp("%04d/%02d/%02d %02d:%02d:%02d.%03d %05d,", sysTime.wYear, sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds, GetCurrentThreadId()); +#else + time_t ltime; + ltime=time(<ime); + + struct tm result={0}; + localtime_r(<ime, &result); + + struct timeval curTime; + gettimeofday(&curTime, NULL); + int milliseconds = curTime.tv_usec / 1000; + + stdstr_f timestamp("%04d/%02d/%02d %02d:%02d:%02d.%03d %05d,", result.tm_year+1900, result.tm_mon+1, result.tm_mday, result.tm_hour, result.tm_min, result.tm_sec, milliseconds, GetCurrentThreadId()); +#endif m_hLogFile.Log(timestamp.c_str()); m_hLogFile.Log(TraceSeverity(severity)); diff --git a/Source/Common/Trace.h b/Source/Common/Trace.h index 3d1b310ce..e1744cd0d 100644 --- a/Source/Common/Trace.h +++ b/Source/Common/Trace.h @@ -11,6 +11,10 @@ enum TraceSeverity TraceVerbose = 0x00000006, }; +#ifndef _MSC_VER +#define __interface struct +#endif + __interface CTraceModule { virtual void Write(uint32_t module, uint8_t severity, const char * file, int line, const char * function, const char * Message) = 0;