LuaLogging
A simple API to use logging features in Lua.

SQL appender

The SQL appender can be used to write log messages to a SQL database table. It uses LuaSQL, therefore any database supported by LuaSQL can be used.

function logging.sql{
    connectionfactory = function,
    [tablename = string,]
    [logdatefield = string,]
    [loglevelfield = string,]
    [logmessagefield = string,]
    [keepalive = boolean,]

    [logLevel = log-level-constant,]
}
  • connectionfactory:
    This must be a function that creates a LuaSQL connection object. This function will be called everytime a connection needs to be created.
  • tablename:
    The name of the table to write the log requests. Default value is "LogTable".
  • logdatefield:
    The name of the field to write the date of each log request. Default value is "LogDate".
  • loglevelfield:
    The name of the field to write the level of each log request. Default value is "LogLevel".
  • logmessagefield:
    The name of the field to write the message of each log request. Default value is "LogMessage".
  • keepalive:
    In every log request a connection to the database is opened, the message is written, and the connection is closed.
    If the user wants to keep the connection opened he can specify keepalive = true.
  • logLevel:
    The initial log-level to set for the created logger.

Example

require"logging.sql"
require"luasql.jdbc"

local env, err = luasql.jdbc('com.mysql.jdbc.Driver')

local logger = logging.sql {
  connectionfactory = function()
    local con, err = env:connect('jdbc:mysql://localhost/test',
                                 'tcp', '123')
    assert(con, err)
    return con
  end,
  keepalive = true,
}

logger:info("logging.sql test")
logger:debug("debugging...")
logger:error("error!")

XHTML 1.0 válido!