feat: Add log category filtering for enhanced logging control
- Introduced a new command-line flag for specifying log categories, allowing users to filter logs based on selected categories. - Implemented parsing of the comma-separated log categories string in the main application. - Enhanced the LogManager to support category-specific logging and added console output to indicate which categories are enabled for debugging.
This commit is contained in:
@@ -25,6 +25,10 @@ using namespace yaze;
|
||||
DEFINE_FLAG(std::string, rom_file, "", "The ROM file to load.");
|
||||
DEFINE_FLAG(std::string, log_file, "", "Output log file path for debugging.");
|
||||
DEFINE_FLAG(bool, debug, false, "Enable debug logging and verbose output.");
|
||||
DEFINE_FLAG(std::string, log_categories, "",
|
||||
"Comma-separated list of log categories to enable. "
|
||||
"If empty, all categories are logged. "
|
||||
"Example: --log_categories=\"Room,DungeonEditor\" to filter noisy logs.");
|
||||
DEFINE_FLAG(std::string, editor, "",
|
||||
"The editor to open on startup. "
|
||||
"Available editors: Assembly, Dungeon, Graphics, Music, Overworld, "
|
||||
@@ -68,8 +72,23 @@ int main(int argc, char **argv) {
|
||||
yaze::util::LogLevel log_level = FLAGS_debug->Get()
|
||||
? yaze::util::LogLevel::YAZE_DEBUG
|
||||
: yaze::util::LogLevel::INFO;
|
||||
|
||||
// Parse log categories from comma-separated string
|
||||
std::set<std::string> log_categories;
|
||||
std::string categories_str = FLAGS_log_categories->Get();
|
||||
if (!categories_str.empty()) {
|
||||
size_t start = 0;
|
||||
size_t end = categories_str.find(',');
|
||||
while (end != std::string::npos) {
|
||||
log_categories.insert(categories_str.substr(start, end - start));
|
||||
start = end + 1;
|
||||
end = categories_str.find(',', start);
|
||||
}
|
||||
log_categories.insert(categories_str.substr(start));
|
||||
}
|
||||
|
||||
yaze::util::LogManager::instance().configure(log_level, FLAGS_log_file->Get(),
|
||||
{});
|
||||
log_categories);
|
||||
|
||||
// Enable console logging via feature flag if debug is enabled.
|
||||
if (FLAGS_debug->Get()) {
|
||||
|
||||
@@ -50,6 +50,14 @@ void LogManager::configure(LogLevel level, const std::string& file_path,
|
||||
} else {
|
||||
all_categories_enabled_.store(false);
|
||||
enabled_categories_ = categories;
|
||||
|
||||
// Log which categories are enabled for debugging
|
||||
std::string category_list;
|
||||
for (const auto& cat : categories) {
|
||||
if (!category_list.empty()) category_list += ", ";
|
||||
category_list += cat;
|
||||
}
|
||||
std::cerr << "Log categories filter enabled: [" << category_list << "]" << std::endl;
|
||||
}
|
||||
|
||||
// If a file path is provided, close any existing stream and open the new file.
|
||||
|
||||
Reference in New Issue
Block a user