-- assign filename variable
-- or as Lua does not seem to know about the PID or PPID environment variables
-- and if you have several recursor processes you can use the os.tmpname()
-- function to get something starting with lua_
logfilename="/var/tmp/my.log"
-- open a file handle for writing
local querylog=assert(io.open(logfilename, "w"))
-- enable buffering for said file handle
querylog:setvbuf("full")
-- a list of our CIDR ranges that we want to _exclude_ from being logged
ourranges={
	"4.0.0.0/8",
	"8.0.0.0/8",
}
-- the preresolve hook is where the recursor jumps before even looking into the cache
function preresolve ( ip, destination, domain, qtype )
	-- we want to log everything that arrives for 4.3.2.1
	if
	        destination == "4.3.2.1"      -- comment
	then
		-- for added value we are using YYYYMMDDHHMMSS style timestamps
		d=os.date("\"%Y%m%d%H%M%S\"")
		-- write what we know to the file
		io.output(querylog):write(d, " four-three-two-one \"", destination, "\" \"", ip, "\" \"", qtype, "\" \"", domain, "\"\n")
	end
	-- we want to log everything that is _not_ from the CIDR ranges mentioned above
	-- strip the _not_ and it works the other way around of course
	if not matchnetmask(ip, ourranges)
	then
		d=os.date("\"%Y%m%d%H%M%S\"")
		io.output(querylog):write(d, " notournets \"", destination, "\" \"", ip, "\" \"", qtype, "\" \"", domain, "\"\n")
	end
	-- this is important, we need to signal the recursor that we did _not_ answer the query
	return -1, {}
end