Logging adjustments

This commit is contained in:
Chris Miles 2025-06-30 03:07:31 -05:00
parent 6238293f22
commit 278f61e17e
2 changed files with 63 additions and 141 deletions

View File

@ -970,7 +970,7 @@ void WorldContentService::LoadTargetedRulesets()
m_rule_manager->SetRule(r.rule_name, r.rule_value); m_rule_manager->SetRule(r.rule_name, r.rule_value);
LogInfo( LogInfo(
"Loading targeted rule from ruleset [{}] ruleset_name [{}] rule_name [{}] rule_value [{}]", "Loaded [{}] ruleset [{}] name [{}] value [{}]",
e.ruleset_id, e.ruleset_id,
e.name, e.name,
r.rule_name, r.rule_name,

View File

@ -224,48 +224,22 @@ void EQEmuLogSys::ProcessConsoleMessage(
const char *file, const char *file,
const char *func, const char *func,
int line int line
) ) {
{
bool is_error = ( bool is_error = (
log_category == Logs::LogCategory::Error || log_category == Logs::LogCategory::Error ||
log_category == Logs::LogCategory::MySQLError || log_category == Logs::LogCategory::MySQLError ||
log_category == Logs::LogCategory::Crash || log_category == Logs::LogCategory::Crash ||
log_category == Logs::LogCategory::QuestErrors log_category == Logs::LogCategory::QuestErrors
); );
bool is_warning = ( bool is_warning = (log_category == Logs::LogCategory::Warning);
log_category == Logs::LogCategory::Warning
);
(!is_error ? std::cout : std::cerr) std::ostream &out = (!is_error ? std::cout : std::cerr);
<< ""
<< rang::fgB::black
<< rang::style::bold
<< fmt::format("{:>6}", GetPlatformName().substr(0, 6))
<< rang::style::reset
<< rang::fgB::gray
<< " | "
<< ((is_error || is_warning) ? rang::fgB::red : rang::fgB::gray)
<< rang::style::bold
<< fmt::format("{:^10}", fmt::format("{}", Logs::LogCategoryName[log_category]).substr(0, 10))
<< rang::style::reset
<< rang::fgB::gray
<< " | "
<< rang::fgB::gray
<< rang::style::bold
<< fmt::format("{}", func)
<< rang::style::reset
<< rang::fgB::gray
<< " ";
if (RuleB(Logging, PrintFileFunctionAndLine)) { out << rang::style::bold << rang::fgB::gray
(!is_error ? std::cout : std::cerr) << GetPlatformName() << " "
<< "" << Logs::LogCategoryName[log_category] << " "
<< rang::fgB::green << rang::fgB::gray << func << " "
<< rang::style::bold << rang::style::reset;
<< fmt::format("{:}", fmt::format("{}:{}:{}", std::filesystem::path(file).filename().string(), func, line))
<< rang::style::reset
<< " | ";
}
if (log_category == Logs::LogCategory::MySQLQuery) { if (log_category == Logs::LogCategory::MySQLQuery) {
auto s = Strings::Split(message, "--"); auto s = Strings::Split(message, "--");
@ -273,132 +247,79 @@ void EQEmuLogSys::ProcessConsoleMessage(
std::string query = Strings::Trim(s[0]); std::string query = Strings::Trim(s[0]);
std::string meta = Strings::Trim(s[1]); std::string meta = Strings::Trim(s[1]);
std::cout << out << rang::fgB::green << query << rang::style::reset;
rang::fgB::green out << rang::fgB::black << " -- " << meta << rang::style::reset;
<<
query
<<
rang::style::reset;
std::cout <<
rang::fgB::black
<<
" -- "
<<
meta
<<
rang::style::reset;
} }
} } else {
else if (Strings::Contains(message, "[")) { std::vector<std::string> tokens = Strings::Split(message, " ");
for (auto &e: Strings::Split(message, " ")) {
if (Strings::Contains(e, "[") && Strings::Contains(e, "]")) {
e = Strings::Replace(e, "[", "");
e = Strings::Replace(e, "]", "");
bool is_upper = false; for (auto &token : tokens) {
bool has_brackets = Strings::Contains(token, "[") && Strings::Contains(token, "]");
std::string clean_token = Strings::Replace(Strings::Replace(token, "[", ""), "]", "");
for (int i = 0; i < strlen(e.c_str()); i++) { // Bracket formatting
if (isupper(e[i])) { if (has_brackets) {
is_upper = true; static std::map<std::string, rang::fgB> color_tags = {
} {"<black>", rang::fgB::black},
} {"<green>", rang::fgB::green},
{"<yellow>", rang::fgB::yellow},
// color matching in [] {"<blue>", rang::fgB::blue},
// ex: [<red>variable] would produce [variable] with red inside brackets
std::map<std::string, rang::fgB> colors = {
{"<black>", rang::fgB::black},
{"<green>", rang::fgB::green},
{"<yellow>", rang::fgB::yellow},
{"<blue>", rang::fgB::blue},
{"<magenta>", rang::fgB::magenta}, {"<magenta>", rang::fgB::magenta},
{"<cyan>", rang::fgB::cyan}, {"<cyan>", rang::fgB::cyan},
{"<gray>", rang::fgB::gray}, {"<gray>", rang::fgB::gray},
{"<red>", rang::fgB::red}, {"<red>", rang::fgB::red},
}; };
bool match_color = false; static std::map<std::string, rang::fgB> keyword_matches = {
for (auto &c: colors) {
if (Strings::Contains(e, c.first)) {
e = Strings::Replace(e, c.first, "");
(!is_error ? std::cout : std::cerr)
<< rang::fgB::gray
<< "["
<< rang::style::bold
<< c.second
<< e
<< rang::style::reset
<< rang::fgB::gray
<< "] ";
match_color = true;
}
}
// string match to colors
std::map<std::string, rang::fgB> matches = {
{"missing", rang::fgB::red}, {"missing", rang::fgB::red},
{"error", rang::fgB::red}, {"error", rang::fgB::red},
{"ok", rang::fgB::green}, {"ok", rang::fgB::green},
}; };
for (auto &c: matches) { bool matched = false;
if (Strings::Contains(e, c.first)) {
(!is_error ? std::cout : std::cerr) for (auto &[tag, color] : color_tags) {
<< rang::fgB::gray if (Strings::Contains(clean_token, tag)) {
<< "[" clean_token = Strings::Replace(clean_token, tag, "");
<< rang::style::bold out << rang::fgB::gray << "["
<< c.second << rang::style::bold << color << clean_token
<< e << rang::style::reset << rang::fgB::gray << "] ";
<< rang::style::reset matched = true;
<< rang::fgB::gray break;
<< "] ";
match_color = true;
} }
} }
// if we don't match a color in either the string matching or if (!matched) {
// the color tag matching, we default to yellow inside brackets for (auto &[keyword, color] : keyword_matches) {
// if uppercase, does not get colored if (Strings::Contains(clean_token, keyword)) {
if (!match_color) { out << rang::fgB::gray << "["
if (!is_upper) { << rang::style::bold << color << clean_token
(!is_error ? std::cout : std::cerr) << rang::style::reset << rang::fgB::gray << "] ";
<< rang::fgB::gray matched = true;
<< "[" break;
<< rang::style::bold }
<< rang::fgB::yellow
<< e
<< rang::style::reset
<< rang::fgB::gray
<< "] ";
}
else {
(!is_error ? std::cout : std::cerr) << rang::fgB::gray << "[" << e << "] ";
} }
} }
}
else { if (!matched) {
(!is_error ? std::cout : std::cerr) bool is_upper = std::any_of(clean_token.begin(), clean_token.end(), ::isupper);
<< (is_error ? rang::fgB::red : rang::fgB::gray) if (!is_upper) {
<< e out << rang::fgB::gray << "["
<< " "; << rang::style::bold << rang::fgB::yellow << clean_token
<< rang::style::reset << rang::fgB::gray << "] ";
} else {
out << rang::fgB::gray << "[" << clean_token << "] ";
}
}
} else {
out << (is_error ? rang::fgB::red : rang::fgB::gray) << token << " ";
} }
} }
} }
else {
(!is_error ? std::cout : std::cerr)
<< (is_error ? rang::fgB::red : rang::fgB::gray)
<< message
<< " ";
}
if (!origination_info.zone_short_name.empty()) { if (!origination_info.zone_short_name.empty()) {
(!is_error ? std::cout : std::cerr) out << rang::fgB::black << "-- "
<< << fmt::format(
rang::fgB::black
<<
"-- "
<<
fmt::format(
"[{}] ({}) inst_id [{}]", "[{}] ({}) inst_id [{}]",
origination_info.zone_short_name, origination_info.zone_short_name,
origination_info.zone_long_name, origination_info.zone_long_name,
@ -406,11 +327,12 @@ void EQEmuLogSys::ProcessConsoleMessage(
); );
} }
(!is_error ? std::cout : std::cerr) << rang::style::reset << std::endl; out << rang::style::reset << std::endl;
m_on_log_console_hook(log_category, message); m_on_log_console_hook(log_category, message);
} }
/** /**
* @param str * @param str
* @return * @return