From d15c674584a2291303a23bb5d56279a12339c9a7 Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 7 Nov 2017 05:33:10 +0800 Subject: [PATCH] [General] Move getFilenameTimestamp() to Utils --- apps/openmw-mp/main.cpp | 2 +- apps/openmw/main.cpp | 2 +- components/openmw-mp/Log.hpp | 1 - components/openmw-mp/Utils.cpp | 9 +++++++++ components/openmw-mp/Utils.hpp | 2 ++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index 96af274cc..79037a2b8 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) // Redirect cout and cerr to tes3mp server log logfile.open(boost::filesystem::path( - cfgMgr.getLogPath() / "/tes3mp-server-" += Log::getFilenameTimestamp() += ".log")); + cfgMgr.getLogPath() / "/tes3mp-server-" += Utils::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 d482dcf6d..328cdef55 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -393,7 +393,7 @@ int main(int argc, char**argv) that includes a timestamp */ // Redirect cout and cerr to tes3mp client log - logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/tes3mp-client-" += Log::getFilenameTimestamp() += ".log")); + logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/tes3mp-client-" += Utils::getFilenameTimestamp() += ".log")); /* End of tes3mp change (major) */ diff --git a/components/openmw-mp/Log.hpp b/components/openmw-mp/Log.hpp index c2a648037..54e834570 100644 --- a/components/openmw-mp/Log.hpp +++ b/components/openmw-mp/Log.hpp @@ -48,7 +48,6 @@ public: void SetLevel(int level); void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const; - static std::string getFilenameTimestamp(); Log(const Log &) = delete; Log &operator=(Log &) = delete; diff --git a/components/openmw-mp/Utils.cpp b/components/openmw-mp/Utils.cpp index a4a4b6e7b..bba0c47ac 100644 --- a/components/openmw-mp/Utils.cpp +++ b/components/openmw-mp/Utils.cpp @@ -196,3 +196,12 @@ string Utils::intToHexStr(unsigned val) sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val; return sstr.str(); } + +string Utils::getFilenameTimestamp() +{ + time_t rawtime = time(nullptr); + struct tm *timeinfo = localtime(&rawtime); + char buffer[25]; + strftime(buffer, 25, "%Y-%m-%d-%H_%M_%S", timeinfo); + return string(buffer); +} diff --git a/components/openmw-mp/Utils.hpp b/components/openmw-mp/Utils.hpp index 448cb13d7..47e264358 100644 --- a/components/openmw-mp/Utils.hpp +++ b/components/openmw-mp/Utils.hpp @@ -40,5 +40,7 @@ namespace Utils void printWithWidth(std::ostringstream &sstr, std::string str, size_t width); std::string intToHexStr(unsigned val); + + std::string getFilenameTimestamp(); } #endif //UTILS_HPP