File: log.lua

package info (click to toggle)
dnsmasq 2.92-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,124 kB
  • sloc: ansic: 37,139; sh: 654; perl: 643; makefile: 210; python: 136; xml: 53
file content (40 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (3)
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
-- Lua script logging calls from dnsmasq

-- Open the log file in append mode 
logfile = assert(io.open("/var/log/dnsmasq-lua.log", "a"))

-- Prepend date and time to a string and write the result to the log file
function __log(str)
	logfile:write(os.date("!%FT%TZ ")..str.."\n")
end

-- flush the log file
function __flush_log()
	logfile:flush()
end

-- Log a call to init()
function init()
	__log("initialising")
	__flush_log()
end

-- Log a call to shutdown()
function shutdown()
	__log("shutting down")
	__flush_log()
end

-- Log a call to lease() including all arguments
function lease(operation, params)
	local lines = {}
	__log(operation.." lease")
	for key,value in pairs(params) do
		table.insert(lines, key..": "..value)
	end
	table.sort(lines)
	for index,line in ipairs(lines) do
		__log("\t"..line)
	end
	__flush_log()
end