2022-01-17 20:06:00 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
|
|
|
#include <hex/helpers/file.hpp>
|
2022-03-04 11:36:37 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2022-01-17 20:06:00 +01:00
|
|
|
#include <hex/helpers/fmt.hpp>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace hex::log {
|
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
static fs::File g_loggerFile;
|
2022-01-17 20:06:00 +01:00
|
|
|
|
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;
|
|
|
|
|
2022-03-04 11:36:37 +01:00
|
|
|
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Logs, true)) {
|
|
|
|
fs::createDirectories(path);
|
|
|
|
g_loggerFile = fs::File(path / hex::format("{0:%Y%m%d_%H%M%S}.log", fmt::localtime(std::chrono::system_clock::now())), fs::File::Mode::Create);
|
2022-03-01 00:03:28 +01:00
|
|
|
g_loggerFile.disableBuffering();
|
2022-01-17 20:06:00 +01:00
|
|
|
|
|
|
|
if (g_loggerFile.isValid()) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|