Ticket #3255: t3255_use_datetime_in_simlog_directory.patch
File t3255_use_datetime_in_simlog_directory.patch, 1.8 KB (added by , 9 years ago) |
---|
-
source/ps/Replay.cpp
31 31 #include "scriptinterface/ScriptInterface.h" 32 32 #include "scriptinterface/ScriptStats.h" 33 33 #include "simulation2/Simulation2.h" 34 34 #include "simulation2/helpers/SimulationCommand.h" 35 35 36 #include <ctime> 36 37 #include <sstream> 37 38 #include <fstream> 38 39 #include <iomanip> 39 40 40 41 #if MSC_VERSION 41 42 #include <process.h> 42 #define getpid _getpid // use the non-deprecated function name43 43 #endif 44 44 45 45 static std::string Hexify(const std::string& s) 46 46 { 47 47 std::stringstream str; … … 52 52 } 53 53 54 54 CReplayLogger::CReplayLogger(ScriptInterface& scriptInterface) : 55 55 m_ScriptInterface(scriptInterface) 56 56 { 57 // Construct the directory name based on the PID, to be relatively unique. 58 // Append "-1", "-2" etc if we run multiple matches in a single session, 59 // to avoid accidentally overwriting earlier logs. 60 61 std::wstringstream name; 62 name << getpid(); 63 64 static int run = -1; 65 if (++run) 66 name << "-" << run; 57 // Get current date and time 58 time_t t = time(NULL); 59 struct tm* now = localtime(&t); 60 char currentDateTime[20]; 61 sprintf_s(currentDateTime, ARRAY_SIZE(currentDateTime), "%04d-%02d-%02d_%02d-%02d-%02d", 1900+now->tm_year, 1+now->tm_mon, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec); 67 62 68 OsPath path = psLogDir() / L"sim_log" / name.str() / L"commands.txt"; 63 // Create commands.txt 64 OsPath path = psLogDir() / L"sim_log" / currentDateTime / L"commands.txt"; 69 65 CreateDirectories(path.Parent(), 0700); 70 66 m_Stream = new std::ofstream(OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); 71 67 } 72 68 73 69 CReplayLogger::~CReplayLogger()