turbo.log – Command-line log helper

A simple log writer implementation with different levels and standard formatting. Messages written is appended to level and timestamp. You can turn off unwanted categories by modifiying the table at log.categories.

For messages shorter than 4096 bytes a static buffer is used to improve performance. C time.h functions are used as Lua builtin’s is not compiled by LuaJIT. This statement applies to all log functions, except log.dump.

Example output: [S 2013/07/15 18:58:03] [web.lua] 200 OK GET / (127.0.0.1) 0ms

To enable or disable categories, modify the table in turbo.log.categories.

As default, it is declared as such:

log = {
    ["categories"] = {
        -- Enable or disable global log categories.
        -- The categories can be modified at any time.
        ["success"] = true,
        ["notice"] = true,
        ["warning"] = true,
        ["error"] = true,
        ["debug"] = true,
        ["development"] = false
    }
}
success(str)

Log to stdout. Success category. Use for successfull events etc. Messages are printed with green color.

Parameters:str (String) – Log string.
notice(str)

Log to stdout. Notice category. Use for notices, typically non-critical messages to give a hint. Messages are printed with white color.

Parameters:str (String) – Log string.
warning(str)

Log to stderr. Warning category. Use for warnings. Messages are printed with yellow color.

Parameters:str (String) – Log string.
error(str)

Log to stderr. Error category. Use for critical errors, when something is clearly wrong. Messages are printed with red color.

Parameters:str (String) – Log string.
debug(str)

Log to stdout. Debug category. Use for debug messages not critical for releases.

Parameters:str (String) – Log string.
devel(str)

Log to stdout. Development category. Use for development purpose messages. Messages are printed with cyan color.

Parameters:str (String) – Log string.
stringify(t, name, indent)

Stringify Lua table.

Parameters:
  • t (Table) – Lua table
  • name (String) – Optional identifier for table.
  • indent (Number) – Optional indent level.
Return type:

String