Add "caller" paramteter to logger

This commit is contained in:
themodernhakr 2025-03-11 14:43:14 -05:00
parent daa70062f6
commit 5468fa9605

View File

@ -1,18 +1,18 @@
@lazy @lazy
function logger(type, message) { function logger(type, caller, message) {
$tmp_logger = false; $tmp_logger = false;
if ($logger) { $tmp_logger = $type; } if ($logger) { $tmp_logger = $type; }
switch($tmp_logger) { switch($tmp_logger) {
case 5: case 5:
say "FATAL: $message"; say "FATAL: ($caller) $message";
case 4: case 4:
say "ERROR: $message"; say "ERROR: ($caller) $message";
case 3: case 3:
say "WARNING: $message"; say "WARNING: ($caller) $message";
case 2: case 2:
say "INFO: $message"; say "INFO: ($caller) $message";
case 1: case 1:
say "DEBUG: $message"; say "DEBUG: ($caller) $message";
default: default:
return 0; return 0;
} }
@ -25,7 +25,7 @@ class logger {
$logger = false; $logger = false;
} else if ($logger) { } else if ($logger) {
say "Logging is enabled. You should now see a test log message:"; say "Logging is enabled. You should now see a test log message:";
logger(2, "This is a test. Logging appears to be working as expected!"); logger(2, "logger", "This is a test. Logging appears to be working as expected!");
} else { } else {
say "This is not a log message. There appears to be something wrong with the logger. It has not been detected as `!true` or `true`. Please investigate."; say "This is not a log message. There appears to be something wrong with the logger. It has not been detected as `!true` or `true`. Please investigate.";
} }
@ -52,23 +52,23 @@ class logger {
} }
function test_fatal() { function test_fatal() {
logger(5, "This is a test"); logger(5, "logger", "This is a test");
} }
function test_error() { function test_error() {
logger(4, "This is a test"); logger(4, "logger", "This is a test");
} }
function test_warning() { function test_warning() {
logger(3, "This is a test"); logger(3, "logger", "This is a test");
} }
function test_info() { function test_info() {
logger(2, "This is a test"); logger(2, "logger", "This is a test");
} }
function test_debug() { function test_debug() {
logger(1, "This is a test"); logger(1, "logger", "This is a test");
} }
} }