Skip to content

Instantly share code, notes, and snippets.

@soapdog
Created February 11, 2017 18:16
Show Gist options
  • Save soapdog/1199099f865a96aab974d7b45db4ffe4 to your computer and use it in GitHub Desktop.
Save soapdog/1199099f865a96aab974d7b45db4ffe4 to your computer and use it in GitHub Desktop.
little query logger for sailor
--------------------------------------------------------------------------------
-- query_logger.lua, v0.1.0: A quick and dirty logger to help with query debuging
-- This file is a part of Sailor project
-- Copyright (c) 2017 Andre Garzia <[email protected]>
-- License: MIT
-- http://sailorproject.org
--------------------------------------------------------------------------------
local sailor = require "sailor"
local main_conf = require "conf.conf"
local conf = main_conf.db[main_conf.sailor.environment]
local log_file_path = (sailor.path..'/runtime/logs')
local query_logger = {
outfile = "query.log"
}
function query_logger.write(query) {
local fp,err = io.open(logger.outfile, "a")
local str = string.format("[QUERY %s] %s\n",
os.date(), query)
if fp then
fp:write(str)
fp:close()
else
error("Couldn't open logfile:" .. err)
end
}
function query_logger.is_logger_enabled() {
return conf.log_database_queries
}
return query_logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment