Use new getFilenameStamp() method to generate timestamps for filenames

coverity_scan^2
David Cernat 8 years ago
parent 3932654d5d
commit 253ded1ee3

@ -9,7 +9,6 @@
#include <components/openmw-mp/NetworkMessages.hpp>
#include <apps/openmw-mp/Script/Script.hpp>
#include <iostream>
#include <ctime>
#include <components/files/configurationmanager.hpp>
#include <components/settings/settings.hpp>
#include <boost/iostreams/concepts.hpp>
@ -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));

@ -1,6 +1,5 @@
#include <iostream>
#include <cstdio>
#include <ctime>
#include <components/version/version.hpp>
#include <components/files/configurationmanager.hpp>
@ -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));

@ -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;
}

@ -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

Loading…
Cancel
Save