debug::Logger

This commit is contained in:
MihailRis
2024-04-04 18:19:19 +03:00
parent f298d6ef1d
commit 0c411cf227
16 changed files with 233 additions and 51 deletions
+14 -5
View File
@@ -13,13 +13,18 @@
#include "files/engine_paths.h"
#include "util/platform.h"
#include "util/command_line.h"
#include "debug/Logger.h"
#define SETTINGS_FILE "settings.toml"
#define CONTROLS_FILE "controls.json"
static debug::Logger logger("main");
namespace fs = std::filesystem;
int main(int argc, char** argv) {
debug::Logger::init("latest.log");
EnginePaths paths;
if (!parse_cmdline(argc, argv, paths))
return EXIT_SUCCESS;
@@ -33,7 +38,7 @@ int main(int argc, char** argv) {
fs::path settings_file = userfiles/fs::path(SETTINGS_FILE);
fs::path controls_file = userfiles/fs::path(CONTROLS_FILE);
if (fs::is_regular_file(settings_file)) {
std::cout << "-- loading settings" << std::endl;
logger.info() << "loading settings";
std::string text = files::read_string(settings_file);
toml::Reader reader(wrapper.get(), settings_file.string(), text);
reader.read();
@@ -41,19 +46,23 @@ int main(int argc, char** argv) {
corecontent::setup_bindings();
Engine engine(settings, &paths);
if (fs::is_regular_file(controls_file)) {
std::cout << "-- loading controls" << std::endl;
logger.info() << "loading controls";
std::string text = files::read_string(controls_file);
load_controls(controls_file.string(), text);
}
engine.mainloop();
std::cout << "-- saving settings" << std::endl;
logger.info() << "saving settings";
files::write_string(settings_file, wrapper->write());
files::write_string(controls_file, write_controls());
}
catch (const initialize_error& err) {
std::cerr << "could not to initialize engine" << std::endl;
std::cerr << err.what() << std::endl;
logger.error() << "could not to initialize engine\n" << err.what();
}
catch (const std::exception& err) {
logger.error() << "uncaught exception: " << err.what();
debug::Logger::flush();
throw;
}
return EXIT_SUCCESS;
}