diff --git a/html.lua b/html.lua
index d317aa5..da43d7f 100644
--- a/html.lua
+++ b/html.lua
@@ -1,3 +1,4 @@
+local logger = require(".logging")
 
 local function trim(str)
 	return str:match("^%s*(.-)%s*$")
@@ -232,7 +233,7 @@ function M.tokenise( content )
 
 					if TOKENS[#TOKENS] and ( TOKENS[#TOKENS].type == "START_OPENING_TAG") then
 						if RAW_TEXT_TAGS[word] then
-							print("Warning: "..word.." tags may contain text that would be incorrectly parsed as HTML.")
+							logger.printerr("Warning: "..word.." tags may contain text that would be incorrectly parsed as HTML.")
 							-- made possible because of the whitespace removal at the start
 							set_skipping_to("" .. word)
 						end
@@ -263,7 +264,7 @@ function M.tokenise( content )
 
 					if TOKENS[#TOKENS] and ( TOKENS[#TOKENS].type == "START_OPENING_TAG" ) then
 						if RAW_TEXT_TAGS[word] then
-							print("Warning: "..word.." tags may contain text that would be incorrectly parsed as HTML.")
+							logger.printerr("Warning: "..word.." tags may contain text that would be incorrectly parsed as HTML.")
 							-- made possible because of the whitespace removal at the start
 							set_skipping_to("" .. word)
 							text_memory = ""
@@ -401,7 +402,7 @@ function M.parse_tokens_into_document( TOKENS )
 
 				if curr_elem.parent == nil then
 					-- reached DOCUMENT root
-					print("Warning: reached document root while trying to match for closing " .. token.value .. " token.")
+					logger.printerr("Warning: reached document root while trying to match for closing " .. token.value .. " token.")
 					current_doc_element = DOCUMENT
 				else
 					current_doc_element = curr_elem.parent
@@ -582,8 +583,6 @@ function M._tostring(node, indent, include_internal_pseudoelements)
 		node_name = node_name .. ">"
 	end
 
-	--print( node_name )
-
 	local next_indent = indent + 1
 	if is_pseudo_element and not include_internal_pseudoelements then
 		next_indent = indent
diff --git a/logging.lua b/logging.lua
new file mode 100644
index 0000000..afabf23
--- /dev/null
+++ b/logging.lua
@@ -0,0 +1,31 @@
+
+local may_print_errors = false
+local errors_buffer = {}
+
+local logger = {
+	print = function( str )
+		print( str )
+	end,
+	printerr = function( str)
+		if str:sub(#str,#str) ~= "\n" then
+			str = str .. "\n"
+		end
+
+		if not may_print_errors then
+			table.insert(errors_buffer, str)
+			return
+		end
+
+		io.stderr:write(str)
+	end,
+	enable_printing_errors = function()
+		may_print_errors = true
+
+		for _, err in ipairs(errors_buffer) do
+				io.stderr:write(err)
+		end
+	end,
+}
+
+
+return logger