summaryrefslogtreecommitdiff
path: root/tnslc/logging.tnsl
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2023-07-07 15:50:30 -0400
committerKyle Gunger <kgunger12@gmail.com>2023-07-07 15:50:30 -0400
commitceaeb8df4d9bf9b518239ea623d813add5a71072 (patch)
tree7061a06dc67b2832248a36d842b051a408a5a5cd /tnslc/logging.tnsl
parent34066553843ee869d71f24646eea1bac319225d6 (diff)
Returns inside of complex operations
Diffstat (limited to 'tnslc/logging.tnsl')
-rw-r--r--tnslc/logging.tnsl65
1 files changed, 65 insertions, 0 deletions
diff --git a/tnslc/logging.tnsl b/tnslc/logging.tnsl
new file mode 100644
index 0000000..7a60364
--- /dev/null
+++ b/tnslc/logging.tnsl
@@ -0,0 +1,65 @@
+##
+## LOG UTILITIES
+##
+
+# Log levels:
+# 0 - Visual queues and errors only
+# 1 - Info (default)
+# 2 - Debugging information (useful for me, probably less for you)
+# 3 - Also logs the state changes of the log itself
+int log_level = 2
+int log_mode = 1
+
+{}uint8 _log_print_one = "\0\0"
+{}uint8 _log_nl = "\n\0"
+{}uint8 _log_prefix = "[TNSLC] [%d] \0"
+
+/; log_state(int new_state)
+ /; if (new_state !== log_mode)
+ _printf(~_log_nl{0})
+ ;/
+
+ log_mode = new_state
+;/
+
+/; log_err (~uint8 msg)
+ log_state(0)
+ _print_num(~_log_prefix{0}, log_mode)
+ _printf(msg)
+ _printf(~_log_nl{0})
+;/
+
+/; log_info (~uint8 msg)
+ /; if (log_level > 0)
+ log_state(1)
+ _print_num(~_log_prefix{0}, log_mode)
+ _printf(msg)
+ _printf(~_log_nl{0})
+ ;/
+;/
+
+/; log_vis (~uint8 msg)
+ log_state(0)
+ _printf(msg)
+;/
+
+/; log_debug (~uint8 msg)
+ /; if (log_level > 1)
+ log_state(2)
+ _print_num(~_log_prefix{0}, log_mode)
+ _printf(msg)
+ _printf(~_log_nl{0})
+ ;/
+;/
+
+# bypass logging framework (mostly for in-place debugging)
+
+/; log_one (uint8 c)
+ _log_print_one{0} = c
+ _printf(~_log_print_one{0})
+;/
+
+/; log_one_nl (uint8 c)
+ log_one(c)
+ _printf(~_log_nl{0})
+;/