2022-01-17 20:06:00 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
|
|
|
#include <hex/helpers/file.hpp>
|
|
|
|
#include <hex/helpers/paths.hpp>
|
|
|
|
#include <hex/helpers/fmt.hpp>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace hex::log {
|
|
|
|
|
|
|
|
static File g_loggerFile;
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
FILE *getDestination() {
|
2022-01-17 20:06:00 +01:00
|
|
|
if (g_loggerFile.isValid())
|
|
|
|
return g_loggerFile.getHandle();
|
|
|
|
else
|
|
|
|
return stdout;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isRedirected() {
|
|
|
|
return g_loggerFile.isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void redirectToFile() {
|
|
|
|
if (g_loggerFile.isValid()) return;
|
|
|
|
|
|
|
|
for (const auto &path : hex::getPath(ImHexPath::Logs)) {
|
|
|
|
g_loggerFile = File(path / hex::format("{0:%Y%m%d_%H%M%S}.log", fmt::localtime(std::chrono::system_clock::now())), File::Mode::Create);
|
|
|
|
|
|
|
|
if (g_loggerFile.isValid()) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|