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
+17 -16
View File
@@ -1,6 +1,7 @@
#include "BspHeader.h"
#include "common/dma/dma.h"
#include "common/log/log.h"
#include "decompiler/ObjectFile/LinkedObjectFile.h"
#include "decompiler/util/DecompilerTypeSystem.h"
@@ -215,7 +216,7 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) {
while (word_offset < qwc_total * 4) {
VifCode next(deref_u32(start, word_offset));
fmt::print("{} at: {} bytes, {} qw\n", next.print(), word_offset * 4, word_offset / 4);
lg::debug("{} at: {} bytes, {} qw", next.print(), word_offset * 4, word_offset / 4);
word_offset++;
switch (next.kind) {
case VifCode::Kind::UNPACK_V4_16: {
@@ -231,8 +232,8 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) {
words[1] = deref_u32(start, word_offset++);
u16 unpacked[4];
memcpy(unpacked, words, 8);
fmt::print(" [{:3d} {:3d} {:3d} {:3d}]\n", unpacked[0], unpacked[1], unpacked[2],
unpacked[3]);
lg::debug(" [{:3d} {:3d} {:3d} {:3d}]", unpacked[0], unpacked[1], unpacked[2],
unpacked[3]);
}
} break;
@@ -249,7 +250,7 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) {
words[1] = deref_u32(start, word_offset++);
words[2] = deref_u32(start, word_offset++);
words[3] = deref_u32(start, word_offset++);
fmt::print(" [{:3d} {:3d} {:3d} {:3d}]\n", words[0], words[1], words[2], words[3]);
lg::debug(" [{:3d} {:3d} {:3d} {:3d}]", words[0], words[1], words[2], words[3]);
}
} break;
@@ -264,7 +265,7 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) {
words[0] = deref_u32(start, word_offset++);
words[1] = deref_u32(start, word_offset++);
words[2] = deref_u32(start, word_offset++);
fmt::print(" [{:3d} {:3d} {:3d}]\n", words[0], words[1], words[2]);
lg::debug(" [{:3d} {:3d} {:3d}]", words[0], words[1], words[2]);
}
} break;
@@ -274,7 +275,7 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) {
words[1] = deref_u32(start, word_offset++);
words[2] = deref_u32(start, word_offset++);
words[3] = deref_u32(start, word_offset++);
fmt::print(" row data [{:3d} {:3d} {:3d} {:3d}]\n", words[0], words[1], words[2], words[3]);
lg::debug(" row data [{:3d} {:3d} {:3d} {:3d}]", words[0], words[1], words[2], words[3]);
} break;
case VifCode::Kind::STMOD: {
@@ -293,7 +294,7 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) {
s8 words[4];
u32 all = deref_u32(start, word_offset++);
memcpy(words, &all, 4);
fmt::print(" [{:3d} {:3d} {:3d} {:3d}]\n", words[0], words[1], words[2], words[3]);
lg::debug(" [{:3d} {:3d} {:3d} {:3d}]", words[0], words[1], words[2], words[3]);
}
} break;
case VifCode::Kind::NOP:
@@ -302,7 +303,7 @@ void tfrag_debug_print_unpack(Ref start, int qwc_total) {
ASSERT_MSG(false, fmt::format("unknown: {}", next.print()));
}
}
fmt::print("-------------------------------------------\n");
lg::debug("-------------------------------------------");
}
std::vector<u8> read_dma_chain(Ref& start, u32 qwc) {
@@ -350,22 +351,22 @@ void TFragment::read_from_file(TypedRef ref,
if (stats->debug_print_dma_data) {
// first, common
fmt::print("DMA COMMON {}, {} qwc:\n", dmas[0].label_name, dma_qwc[0]);
lg::info("DMA COMMON {}, {} qwc:", dmas[0].label_name, dma_qwc[0]);
tfrag_debug_print_unpack(dmas[0].ref, dma_qwc[0]);
// next "base"
fmt::print("DMA BASE {}, {} qwc:\n", dmas[1].label_name, dma_qwc[1]);
lg::info("DMA BASE {}, {} qwc:", dmas[1].label_name, dma_qwc[1]);
tfrag_debug_print_unpack(dmas[1].ref, dma_qwc[1]);
// next "level0"
// fmt::print("DMA LEVEL0 {}, {} qwc:\n", dmas[0].label_name, dma_qwc[3]);
// lg::print("DMA LEVEL0 {}, {} qwc:\n", dmas[0].label_name, dma_qwc[3]);
// tfrag_debug_print_unpack(dmas[0].ref, dma_qwc[3]);
// next "level1"
fmt::print("DMA LEVEL1 {}, {} qwc:\n", dmas[2].label_name, dma_qwc[2]);
lg::info("DMA LEVEL1 {}, {} qwc:", dmas[2].label_name, dma_qwc[2]);
tfrag_debug_print_unpack(dmas[2].ref, dma_qwc[2]);
fmt::print("qwc's: {} {} {} {}\n", dma_qwc[0], dma_qwc[1], dma_qwc[2], dma_qwc[3]);
lg::info("qwc's: {} {} {} {}", dma_qwc[0], dma_qwc[1], dma_qwc[2], dma_qwc[3]);
}
num_base_colors = read_plain_data_field<u8>(ref, "num-base-colors", dts);
@@ -404,7 +405,7 @@ void TFragment::read_from_file(TypedRef ref,
// todo shader
ASSERT(num_colors / 4 == color_count);
// fmt::print("colors: {} {} {}\n", num_base_colors, num_level0_colors, num_level1_colors);
// lg::print("colors: {} {} {}\n", num_base_colors, num_level0_colors, num_level1_colors);
if (version == GameVersion::Jak1) {
ASSERT(read_plain_data_field<u8>(ref, "pad0", dts) == 0);
ASSERT(read_plain_data_field<u8>(ref, "pad1", dts) == 0);
@@ -920,7 +921,7 @@ void PrototypeBucketTie::read_from_file(TypedRef ref,
break;
case GameVersion::Jak2:
flags = read_plain_data_field<u16>(ref, "flags", dts);
fmt::print("flag: {}\n", flags);
lg::print("flag: {}\n", flags);
break;
default:
ASSERT(false);
@@ -1576,7 +1577,7 @@ void PrototypeBucketShrub::read_from_file(TypedRef ref,
}
if (flags) {
// lid in misty has flag 2, not sure what it means yet.
fmt::print("proto: {} flags: {}\n", name, flags);
lg::info("proto: {} flags: {}", name, flags);
}
in_level = read_plain_data_field<u16>(ref, "in-level", dts);
utextures = read_plain_data_field<u16>(ref, "utextures", dts);