2022-01-17 20:06:00 +01:00
|
|
|
#include <hex/helpers/logger.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>
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
#include <wolv/io/file.hpp>
|
2022-01-17 20:06:00 +01:00
|
|
|
|
|
|
|
namespace hex::log {
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
static wolv::io::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)) {
|
2023-03-12 18:27:29 +01:00
|
|
|
wolv::io::fs::createDirectories(path);
|
|
|
|
g_loggerFile = wolv::io::File(path / hex::format("{0:%Y%m%d_%H%M%S}.log", fmt::localtime(std::chrono::system_clock::now())), wolv::io::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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|