logs: replace every fmt::print with a lg call instead (#1368)

Favors the `lg` namespace over `fmt` directly, as this will output the
logs to a file / has log levels.

I also made assertion errors go to a file, this unfortunately means
importing `lg` and hence `fmt` which was attempted to be avoided before.
But I'm not sure how else to do this aspect without re-inventing the
file logging.

We have a lot of commented out prints as well that we should probably
cleanup at some point / switch them to trace level and default to `info`
level.

I noticed the pattern of disabling debug logs behind some boolean,
something to consider cleaning up in the future -- if our logs were more
structured (knowing where they are coming from) then a lot this
boilerplate could be eliminated.

Closes #1358
This commit is contained in:
Tyler Wilding
2022-10-01 11:58:36 -04:00
committed by GitHub
parent 4e48ba21c1
commit 4d751af38e
120 changed files with 990 additions and 893 deletions
+13 -13
View File
@@ -69,7 +69,7 @@ int main(int argc, char** argv) {
in_folder = in_folder / config.game_name;
// Verify the in_folder is correct
if (!exists(in_folder)) {
fmt::print("Aborting - 'in_folder' does not exist '{}'\n", in_folder.string());
lg::error("Aborting - 'in_folder' does not exist '{}'", in_folder.string());
return 1;
}
@@ -80,9 +80,9 @@ int main(int argc, char** argv) {
// Warning message if expected ELF isn't found, user could be using bad assets / didn't extract
// the ISO properly
if (!config.expected_elf_name.empty() && !exists(in_folder / config.expected_elf_name)) {
fmt::print(
lg::error(
"WARNING - '{}' does not contain the expected ELF file '{}'. Was the ISO extracted "
"properly or is there a version mismatch?\n",
"properly or is there a version mismatch?",
in_folder.string(), config.expected_elf_name);
}
@@ -90,11 +90,11 @@ int main(int argc, char** argv) {
Timer decomp_timer;
fmt::print("[Mem] Top of main: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] Top of main: {} MB\n", get_peak_rss() / (1024 * 1024));
init_opcode_info();
fmt::print("[Mem] After init: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After init: {} MB\n", get_peak_rss() / (1024 * 1024));
std::vector<fs::path> dgos, objs, strs;
for (const auto& dgo_name : config.dgo_names) {
@@ -113,13 +113,13 @@ int main(int argc, char** argv) {
file_util::create_dir_if_needed(file_util::get_jak_project_dir() / "debug_out");
}
fmt::print("[Mem] After config read: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After config read: {} MB", get_peak_rss() / (1024 * 1024));
// build file database
lg::info("Setting up object file DB...");
ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, strs, config);
fmt::print("[Mem] After DB setup: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After DB setup: {} MB", get_peak_rss() / (1024 * 1024));
// write out DGO file info
file_util::write_text_file(out_folder / "dgo.txt", db.generate_dgo_listing());
@@ -136,10 +136,10 @@ int main(int argc, char** argv) {
// process files (required for all analysis)
db.process_link_data(config);
fmt::print("[Mem] After link data: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After link data: {} MB", get_peak_rss() / (1024 * 1024));
db.find_code(config);
db.process_labels();
fmt::print("[Mem] After code: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After code: {} MB", get_peak_rss() / (1024 * 1024));
// top level decompile (do this before printing asm so we get function names)
if (config.find_functions) {
@@ -168,7 +168,7 @@ int main(int argc, char** argv) {
config.hacks.types_with_bad_inspect_methods);
}
fmt::print("[Mem] After decomp: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After decomp: {} MB", get_peak_rss() / (1024 * 1024));
// write out all symbols
file_util::write_text_file(out_folder / "all-syms.gc", db.dts.dump_symbol_types());
@@ -194,7 +194,7 @@ int main(int argc, char** argv) {
}
}
fmt::print("[Mem] After text: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After text: {} MB", get_peak_rss() / (1024 * 1024));
decompiler::TextureDB tex_db;
if (config.process_tpages || config.levels_extract) {
@@ -206,7 +206,7 @@ int main(int argc, char** argv) {
}
}
fmt::print("[Mem] After textures: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After textures: {} MB", get_peak_rss() / (1024 * 1024));
auto replacements_path = file_util::get_jak_project_dir() / "texture_replacements";
if (fs::exists(replacements_path)) {
tex_db.replace_textures(replacements_path);
@@ -227,7 +227,7 @@ int main(int argc, char** argv) {
config.rip_levels, config.extract_collision, level_out_path);
}
fmt::print("[Mem] After extraction: {} MB\n", get_peak_rss() / (1024 * 1024));
lg::info("[Mem] After extraction: {} MB", get_peak_rss() / (1024 * 1024));
if (!config.audio_dir_file_name.empty()) {
auto streaming_audio_in = in_folder / "VAG";