add function for keeping old logs

pull/133/head
Koncord 8 years ago
parent 973db7c78a
commit f7b4aea85b

@ -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…
Cancel
Save