forked from mirror/openmw-tes3mp
add function for keeping old logs
This commit is contained in:
parent
973db7c78a
commit
f7b4aea85b
2 changed files with 23 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <cstdio>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "Log.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
@ -104,3 +105,21 @@ void Log::print(int level, bool hasPrefix, const char *file, int line, const cha
|
|||
va_end(args);
|
||||
cout << buf.data() << flush;
|
||||
}
|
||||
|
||||
string Log::copyOldLog(boost::filesystem::path path, string name, string extension)
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
fs::directory_iterator end_iter;
|
||||
|
||||
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;
|
||||
}
|
|
@ -5,6 +5,8 @@
|
|||
#ifndef OPENMW_LOG_HPP
|
||||
#define OPENMW_LOG_HPP
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
@ -44,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 copyOldLog(boost::filesystem::path path, std::string name, std::string extension);
|
||||
private:
|
||||
Log(int logLevel);
|
||||
/// Not implemented
|
||||
|
|
Loading…
Reference in a new issue