Allow logging to take storages as message inputs
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s

Message inputs with a leading "::" will be parsed as storages.

All other message inputs will be parsed as strings.
This commit is contained in:
themodernhakr 2025-03-28 12:54:05 -05:00
parent 31f616e110
commit 915988215d

View File

@ -1,11 +1,26 @@
@lazy @lazy
function logger(type, caller, message, body) { function messagePrinter(name, caller, message) {
$tmp_logger = false; ::tmp.string = $message;
$tmp_type = $type; ::tmp.sub = ::tmp.string[0:1];
if ($temp_type > 6 || $temp_type < 1) { if (String.isEqual("ferdinland:ferdinland", "tmp.sub", "::")) {
say "The log type requested does not exist. Please find the caller ($caller) and resolve this issue."; ::temp.message = ::tmp.string[2:];
execute run {
switch($tmp_logger) {
case 5:
say "FATAL: ($caller) $(message)";
case 4:
say "ERROR: ($caller) $(message)";
case 3:
say "WARNING: ($caller) $(message)";
case 2:
say "INFO: ($caller) $(message)";
case 1:
say "DEBUG: ($caller) $(message)";
default:
return 0;
} }
if ($temp_type >= $log_level || $logger) { $tmp_logger = $type; } } with ::temp;
} else {
switch($tmp_logger) { switch($tmp_logger) {
case 5: case 5:
say "FATAL: ($caller) $message"; say "FATAL: ($caller) $message";
@ -20,11 +35,28 @@ function logger(type, caller, message, body) {
default: default:
return 0; return 0;
} }
}
}
@lazy
function logger(type, caller, message, body) {
$tmp_logger = false;
$tmp_type = $type;
if ($temp_type > 6 || $temp_type < 1) {
say "The log type requested does not exist. Please find the caller ($caller) and resolve this issue.";
}
if ($temp_type >= $log_level || $logger) { $tmp_logger = $type; }
if (!$tmp_logger) {
return;
} else {
messagePrinter($type, $caller, $message);
$isBody = $body; $isBody = $body;
if ($isBody) { if ($isBody) {
return;
}
tellraw @a $body; tellraw @a $body;
}
}
} }
class logger { class logger {