5 local io = require 'io'
9 -- This module implements a few useful debug functions for use throughout the
17 -- local variables {{{
19 local outfile = io.output()
22 -- public functions {{{
25 -- Turns on debug output.
33 -- Turns off debug output.
41 -- Redirects output to a file rather than stdout.
42 -- @param file File to write debug output to
43 function set_output(file)
44 outfile = base.assert(io.open(file))
50 -- Output a debug message.
51 -- @param msg_type Arbitrary string corresponding to the type of message
52 -- @param msg Message text
53 -- @param color Which terminal code to use for color output (defaults to
55 function message(msg_type, msg, color)
59 color = color or "\027[1;30m"
65 outfile:write(color .. msg_type .. ": " .. msg .. endcolor .. "\n")
72 -- Signal an error. Writes the error message to the screen in red and calls
74 -- @param msg Error message
77 message("ERR", msg, "\027[0;31m")
84 -- Signal a warning. Writes the warning message to the screen in yellow.
85 -- @param msg Warning message
87 message("WARN", msg, "\027[0;33m")