From 58910fc16d2f4451e7c102ae928338b678b221fd Mon Sep 17 00:00:00 2001
From: NullBite <me@nullbite.com>
Date: Sun, 30 Oct 2022 20:35:03 -0400
Subject: [PATCH] Add basic logging functions

---
 script.lua | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/script.lua b/script.lua
index b19e626..a7652a7 100644
--- a/script.lua
+++ b/script.lua
@@ -14,6 +14,47 @@ ping=pings
 TEXTURE_WIDTH = 256
 TEXTURE_HEIGHT = 256
 
+LOG_LEVEL="INFO"
+
+-- Basic logging --{{{
+
+do
+	logging = {}
+	local loglevels={
+		["SILENT"]=0,
+		["FATAL"]=1,
+		["ERROR"]=2,
+		["WARN"]=3,
+		["INFO"]=4,
+		["DEBUG"]=5,
+		["TRACE"]=6
+	}
+
+	-- default log level
+	local loglevel="INFO"
+
+	function setLogLevel(level)
+		loglevel=loglevels[level] and level or loglevel
+	end
+
+	setLogLevel(LOG_LEVEL)
+
+	local function printLog(severity, message)
+		if (loglevels[loglevel]) >= severity then
+			log("[" .. loglevel .. "] " .. message)
+		end
+	end
+
+	function logging.fatal(message) printLog(1, message) end
+	function logging.error(message) printLog(2, message) end
+	function logging.warn(message) printLog(3, message) end
+	function logging.info(message) printLog(4, message) end
+	function logging.debug(message) printLog(5, message) end
+	function logging.trace(message) printLog(6, message) end
+end
+
+-- }}}
+
 -- utility functions -- {{{
 
 --- Create a string representation of a table