mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-10-01 09:00:58 -04:00
add function for keeping old logs
This commit is contained in:
parent
973db7c78a
commit
f7b4aea85b
@ -9,6 +9,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
#include "Log.hpp"
|
#include "Log.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -104,3 +105,21 @@ 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::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
|
#ifndef OPENMW_LOG_HPP
|
||||||
#define OPENMW_LOG_HPP
|
#define OPENMW_LOG_HPP
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC system_header
|
#pragma GCC system_header
|
||||||
#endif
|
#endif
|
||||||
@ -44,6 +46,8 @@ 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 copyOldLog(boost::filesystem::path path, std::string name, std::string extension);
|
||||||
private:
|
private:
|
||||||
Log(int logLevel);
|
Log(int logLevel);
|
||||||
/// Not implemented
|
/// Not implemented
|
||||||
|
Loading…
x
Reference in New Issue
Block a user