2022-01-17 19:06:00 +00:00
|
|
|
#include <hex/helpers/logger.hpp>
|
2022-03-04 10:36:37 +00:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2022-01-17 19:06:00 +00:00
|
|
|
#include <hex/helpers/fmt.hpp>
|
|
|
|
|
2023-03-12 17:27:29 +00:00
|
|
|
#include <wolv/io/file.hpp>
|
2022-01-17 19:06:00 +00:00
|
|
|
|
|
|
|
namespace hex::log {
|
|
|
|
|
2023-03-12 17:27:29 +00:00
|
|
|
static wolv::io::File g_loggerFile;
|
2022-01-17 19:06:00 +00:00
|
|
|
|
2022-01-24 19:53:17 +00:00
|
|
|
FILE *getDestination() {
|
2022-01-17 19:06:00 +00: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 10:36:37 +00:00
|
|
|
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Logs, true)) {
|
2023-03-12 17:27:29 +00: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-02-28 23:03:28 +00:00
|
|
|
g_loggerFile.disableBuffering();
|
2022-01-17 19:06:00 +00:00
|
|
|
|
|
|
|
if (g_loggerFile.isValid()) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|