This file is indexed.

/usr/share/lua/5.1/logging/sql.lua is in lua-logging 1.3.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-------------------------------------------------------------------------------
-- Saves the logging information in a table using luasql
--
-- @author Thiago Costa Ponte (thiago@ideais.com.br)
--
-- @copyright 2004-2013 Kepler Project
--
-------------------------------------------------------------------------------

local logging = require"logging"

function logging.sql(params)
	params = params or {}
	params.tablename = params.tablename or "LogTable"
	params.logdatefield = params.logdatefield or "LogDate"
	params.loglevelfield = params.loglevelfield or "LogLevel"
	params.logmessagefield = params.logmessagefield or "LogMessage"

	if params.connectionfactory == nil or type(params.connectionfactory) ~= "function" then
		return nil, "No specified connection factory function"
	end

	local con, err
	if params.keepalive then
		con, err = params.connectionfactory()
	end

	return logging.new( function(self, level, message)
		if (not params.keepalive) or (con == nil) then
			con, err = params.connectionfactory()
			if not con then
				return nil, err
			end
		end

		local logDate = os.date("%Y-%m-%d %H:%M:%S")
		local insert  = string.format("INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s')",
			params.tablename, params.logdatefield, params.loglevelfield,
			params.logmessagefield, logDate, level, string.gsub(message, "'", "''"))

		local ret, err = pcall(con.execute, con, insert)
		if not ret then
			con, err = params.connectionfactory()
			if not con then
				return nil, err
			end
			ret, err = con:execute(insert)
			if not ret then
				return nil, err
			end
		end

		if not params.keepalive then
			con:close()
		end

		return true
	end)
end

return logging.sql