diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index 1399a8da9..fba354d24 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -172,15 +171,8 @@ int main(int argc, char *argv[]) boost::filesystem::ofstream logfile; - // Get timestamp to add at the end of the log's filename - time_t rawtime = time(0); - struct tm *timeinfo = localtime(&rawtime); - char buffer[25]; - strftime(buffer, 25, "%Y-%m-%d-%I_%M_%S", timeinfo); - std::string timestamp(buffer); - // Redirect cout and cerr to tes3mp server log - logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/tes3mp-server-" += timestamp += ".log")); + logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/tes3mp-server-" += Log::getFilenameTimestamp() += ".log")); coutsb.open (Tee(logfile, oldcout)); cerrsb.open (Tee(logfile, oldcerr)); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 0109e84d6..96c478c9c 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -335,15 +334,8 @@ int main(int argc, char**argv) std::cout.rdbuf (&sb); std::cerr.rdbuf (&sb); #else - // Get timestamp to add at the end of the log's filename - time_t rawtime = time(0); - struct tm *timeinfo = localtime(&rawtime); - char buffer[25]; - strftime(buffer, 25, "%Y-%m-%d-%I_%M_%S", timeinfo); - std::string timestamp(buffer); - // Redirect cout and cerr to tes3mp client log - logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/tes3mp-client-" += timestamp += ".log")); + logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/tes3mp-client-" += Log::getFilenameTimestamp() += ".log")); coutsb.open (Tee(logfile, oldcout)); cerrsb.open (Tee(logfile, oldcerr)); diff --git a/components/openmw-mp/Log.cpp b/components/openmw-mp/Log.cpp index 9596d0655..88265531b 100644 --- a/components/openmw-mp/Log.cpp +++ b/components/openmw-mp/Log.cpp @@ -105,3 +105,13 @@ void Log::print(int level, bool hasPrefix, const char *file, int line, const cha va_end(args); cout << buf.data() << flush; } + +string Log::getFilenameTimestamp() +{ + time_t rawtime = time(0); + struct tm *timeinfo = localtime(&rawtime); + char buffer[25]; + strftime(buffer, 25, "%Y-%m-%d-%I_%M_%S", timeinfo); + std::string timestamp(buffer); + return timestamp; +} \ No newline at end of file diff --git a/components/openmw-mp/Log.hpp b/components/openmw-mp/Log.hpp index 658046dde..1dc0189c8 100644 --- a/components/openmw-mp/Log.hpp +++ b/components/openmw-mp/Log.hpp @@ -46,6 +46,8 @@ public: static const Log &Get(); static void SetLevel(int level); void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const; + + static std::string getFilenameTimestamp(); private: Log(int logLevel); /// Not implemented