7ce0613977
- Add a new file 'crash.json' to store metadata about the crash, like the log file or project opened - show the log file of the session that caused the crash to the user - Correctly restore the project path
38 lines
1008 B
C++
38 lines
1008 B
C++
#include <hex/helpers/logger.hpp>
|
|
#include <hex/helpers/fs.hpp>
|
|
#include <hex/helpers/fmt.hpp>
|
|
|
|
#include <wolv/io/file.hpp>
|
|
|
|
namespace hex::log {
|
|
|
|
static wolv::io::File g_loggerFile;
|
|
|
|
FILE *getDestination() {
|
|
if (g_loggerFile.isValid())
|
|
return g_loggerFile.getHandle();
|
|
else
|
|
return stdout;
|
|
}
|
|
|
|
wolv::io::File& getFile() {
|
|
return g_loggerFile;
|
|
}
|
|
|
|
bool isRedirected() {
|
|
return g_loggerFile.isValid();
|
|
}
|
|
|
|
void redirectToFile() {
|
|
if (g_loggerFile.isValid()) return;
|
|
|
|
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Logs, true)) {
|
|
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::to_time_t(std::chrono::system_clock::now()))), wolv::io::File::Mode::Create);
|
|
g_loggerFile.disableBuffering();
|
|
|
|
if (g_loggerFile.isValid()) break;
|
|
}
|
|
}
|
|
|
|
} |