mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:19:55 +00:00
Use log filenames w/ timestamps instead of adding numbers to their ends
This commit is contained in:
parent
213bc1e733
commit
3932654d5d
4 changed files with 19 additions and 25 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||||
#include <apps/openmw-mp/Script/Script.hpp>
|
#include <apps/openmw-mp/Script/Script.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ctime>
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
#include <boost/iostreams/concepts.hpp>
|
#include <boost/iostreams/concepts.hpp>
|
||||||
|
@ -171,10 +172,15 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
boost::filesystem::ofstream logfile;
|
boost::filesystem::ofstream logfile;
|
||||||
|
|
||||||
// Redirect cout and cerr to openmw.log
|
// Get timestamp to add at the end of the log's filename
|
||||||
cout << Log::renameOldLog(cfgMgr.getLogPath(), "server", "log") << endl;
|
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);
|
||||||
|
|
||||||
logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/server.log"));
|
// Redirect cout and cerr to tes3mp server log
|
||||||
|
logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/tes3mp-server-" += timestamp += ".log"));
|
||||||
|
|
||||||
coutsb.open (Tee(logfile, oldcout));
|
coutsb.open (Tee(logfile, oldcout));
|
||||||
cerrsb.open (Tee(logfile, oldcerr));
|
cerrsb.open (Tee(logfile, oldcerr));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#include <components/version/version.hpp>
|
#include <components/version/version.hpp>
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
|
@ -334,9 +335,15 @@ int main(int argc, char**argv)
|
||||||
std::cout.rdbuf (&sb);
|
std::cout.rdbuf (&sb);
|
||||||
std::cerr.rdbuf (&sb);
|
std::cerr.rdbuf (&sb);
|
||||||
#else
|
#else
|
||||||
// Redirect cout and cerr to openmw.log
|
// Get timestamp to add at the end of the log's filename
|
||||||
Log::renameOldLog(cfgMgr.getLogPath(), "openmw", "log");
|
time_t rawtime = time(0);
|
||||||
logfile.open (boost::filesystem::path(cfgMgr.getLogPath() / "/openmw.log"));
|
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"));
|
||||||
|
|
||||||
coutsb.open (Tee(logfile, oldcout));
|
coutsb.open (Tee(logfile, oldcout));
|
||||||
cerrsb.open (Tee(logfile, oldcerr));
|
cerrsb.open (Tee(logfile, oldcerr));
|
||||||
|
|
|
@ -105,20 +105,3 @@ void Log::print(int level, bool hasPrefix, const char *file, int line, const cha
|
||||||
va_end(args);
|
va_end(args);
|
||||||
cout << buf.data() << flush;
|
cout << buf.data() << flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Log::renameOldLog(boost::filesystem::path path, string name, string extension)
|
|
||||||
{
|
|
||||||
namespace fs = boost::filesystem;
|
|
||||||
|
|
||||||
std::string fullname = name + "." + extension;
|
|
||||||
|
|
||||||
if (fs::exists(path / fullname))
|
|
||||||
{
|
|
||||||
std::string newname;
|
|
||||||
for (int i = 1; fs::exists(path / (newname = name + boost::lexical_cast<string>(i++) + "." + extension)););
|
|
||||||
|
|
||||||
fs::rename(path / fullname, path / newname);
|
|
||||||
return newname;
|
|
||||||
}
|
|
||||||
return fullname;
|
|
||||||
}
|
|
|
@ -46,8 +46,6 @@ public:
|
||||||
static const Log &Get();
|
static const Log &Get();
|
||||||
static void SetLevel(int level);
|
static void SetLevel(int level);
|
||||||
void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const;
|
void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const;
|
||||||
|
|
||||||
static std::string renameOldLog(boost::filesystem::path path, std::string name, std::string extension);
|
|
||||||
private:
|
private:
|
||||||
Log(int logLevel);
|
Log(int logLevel);
|
||||||
/// Not implemented
|
/// Not implemented
|
||||||
|
|
Loading…
Reference in a new issue