From 5f59e5e2c98ef2ab8768f2243c9bb794bcfce0f2 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Fri, 25 Apr 2014 14:51:29 +0200 Subject: [PATCH] Add logging module/facility support. Change log message format to match with that in print3d logger. --- src/main.lua | 49 +++++++++++----------- src/network/netconfig.lua | 78 ++++++++++++++++++------------------ src/network/signin.lua | 21 +++++----- src/network/wlanconfig.lua | 16 ++++---- src/rest/api/api_config.lua | 14 ++++--- src/rest/api/api_info.lua | 13 +++--- src/rest/api/api_network.lua | 12 +++--- src/rest/api/api_printer.lua | 12 ++++-- src/rest/api/api_sketch.lua | 6 ++- src/rest/api/api_update.lua | 4 +- src/rest/response.lua | 5 ++- src/script/d3d-updater.lua | 10 +++-- src/util/access.lua | 16 ++++---- src/util/logger.lua | 25 +++++++----- src/util/printer.lua | 18 +++++++-- src/util/settings.lua | 40 +++++++++--------- src/util/status.lua | 8 ++-- 17 files changed, 196 insertions(+), 151 deletions(-) diff --git a/src/main.lua b/src/main.lua index d839669..c481a2b 100644 --- a/src/main.lua +++ b/src/main.lua @@ -30,6 +30,7 @@ local updater = require('script.d3d-updater') arg = argStash local postData = nil +local MOD_ABBR = "ENTR" --- Switches to wifi client mode or to access point mode based on availability of known wifi networks. @@ -48,11 +49,11 @@ local function setupAutoWifiMode() local wifiState = wifi.getDeviceState() local netName, netMode = wifiState.ssid, wifiState.mode - log:info("current wifi name: " .. (netName or "") .. ", mode: " .. netMode) + log:info(MOD_ABBR, "current wifi name: " .. (netName or "") .. ", mode: " .. netMode) local apSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) local apMode = (apSsid == netName) and (netMode == 'ap') - log:info("ssid of self: " .. apSsid) + log:info(MOD_ABBR, "ssid of self: " .. apSsid) local scanList,msg = wifi.getScanInfo() if not scanList then @@ -60,7 +61,7 @@ local function setupAutoWifiMode() end local knownSsids = wifi.getConfigs() - -- log:info("current wifi name: " .. (netName or "") .. ", mode: " .. netMode .. ", ssid of self: " .. apSsid) + -- log:info(MOD_ABBR, "current wifi name: " .. (netName or "") .. ", mode: " .. netMode .. ", ssid of self: " .. apSsid) local visNet, knownNet = {}, {} for _,sn in ipairs(scanList) do table.insert(visNet, sn.ssid) @@ -68,8 +69,8 @@ local function setupAutoWifiMode() for _,kn in ipairs(knownSsids) do table.insert(knownNet, kn.ssid .. "/" .. kn.mode) end - log:info("visible networks: " .. table.concat(visNet, ", ")) - log:info("known networks: " .. table.concat(knownNet, ", ")) + log:info(MOD_ABBR, "visible networks: " .. table.concat(visNet, ", ")) + log:info(MOD_ABBR, "known networks: " .. table.concat(knownNet, ", ")) -- if the currently active network is client mode and is also visible, do nothing since it will connect automatically further along the boot process if netMode == 'sta' and netName ~= nil and netName ~= "" and findSsidInList(scanList, netName) then @@ -173,12 +174,12 @@ local function setupLogger() local rv = true if logTargetError then - log:error("could not open logfile '" .. logTargetSetting .. "', using stderr as fallback (" .. logTargetError .. ")") + log:error(MOD_ABBR, "could not open logfile '" .. logTargetSetting .. "', using stderr as fallback (" .. logTargetError .. ")") rv = false end if logLevelError then - log:error("uci config specifies invalid log level '" .. logLevelSetting .. "', using verbose level as fallback") + log:error(MOD_ABBR, "uci config specifies invalid log level '" .. logLevelSetting .. "', using verbose level as fallback") rv = false end @@ -198,7 +199,7 @@ local function init(environment) end if dbgText ~= "" then dbgText = " (" .. dbgText .. " debugging)" end - log:info("=======rest api" .. dbgText .. "=======") + log:info(MOD_ABBR, "=======rest api" .. dbgText .. "=======") if (environment['REQUEST_METHOD'] == 'POST') then local n = tonumber(environment['CONTENT_LENGTH']) @@ -224,48 +225,48 @@ local function main(environment) if rq:getRequestMethod() == 'CMDLINE' and rq:get('autowifi') ~= nil then local version = updater.formatVersion(updater.getCurrentVersion()); - log:info("Doodle3D version: "..util.dump(version)) + log:info(MOD_ABBR, "Doodle3D version: "..util.dump(version)) - log:info("running in autowifi mode") + log:info(MOD_ABBR, "running in autowifi mode") local rv,msg = setupAutoWifiMode() if rv then - log:info("autowifi setup done (" .. msg .. ")") + log:info(MOD_ABBR, "autowifi setup done (" .. msg .. ")") else - log:error("autowifi setup failed (" .. msg .. ")") + log:error(MOD_ABBR, "autowifi setup failed (" .. msg .. ")") end elseif rq:getRequestMethod() == 'CMDLINE' and rq:get('signin') ~= nil then - log:info("running in signin mode") + log:info(MOD_ABBR, "running in signin mode") local ds = wifi.getDeviceState() - log:info(" ds.mode: "..util.dump(ds.mode)) + log:info(MOD_ABBR, " ds.mode: "..util.dump(ds.mode)) if ds.mode == "sta" then - log:info(" attempting signin") + log:info(MOD_ABBR, " attempting signin") local success,msg = Signin.signin() if success then - log:info("Signin successful") + log:info(MOD_ABBR, "Signin successful") else - log:info("Signin failed: "..util.dump(msg)) + log:info(MOD_ABBR, "Signin failed: "..util.dump(msg)) end end elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then - -- log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") + -- log:info(MOD_ABBR, "received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") -- .. "/" .. (rq:getRealApiFunctionName() or "") .. " with arguments: " .. util.dump(rq:getAll())) - log:info("received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") + log:info(MOD_ABBR, "received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "") .. "/" .. (rq:getRealApiFunctionName() or "")) if rq:getRequestMethod() ~= 'CMDLINE' then - log:info("remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort()) - --log:verbose("user agent: " .. rq:getUserAgent()) + log:info(MOD_ABBR, "remote IP/port: " .. rq:getRemoteHost() .. "/" .. rq:getRemotePort()) + --log:verbose(MOD_ABBR, "user agent: " .. rq:getUserAgent()) end local response, err = rq:handle() - if err ~= nil then log:error(err) end + if err ~= nil then log:error(MOD_ABBR, err) end response:send() response:executePostResponseQueue() else - log:info("Nothing to do...bye.\n") + log:info(MOD_ABBR, "Nothing to do...bye.\n") end end @@ -286,7 +287,7 @@ function handle_request(env) resp:setError("initialization failed" .. errSuffix) resp:send() - log:error("initialization failed" .. errSuffix) --NOTE: this assumes the logger has been initialized properly, despite init() having failed + log:error(MOD_ABBR, "initialization failed" .. errSuffix) --NOTE: this assumes the logger has been initialized properly, despite init() having failed return 1 else diff --git a/src/network/netconfig.lua b/src/network/netconfig.lua index 3c2bbb4..14fe69b 100644 --- a/src/network/netconfig.lua +++ b/src/network/netconfig.lua @@ -18,6 +18,8 @@ local reconf = {} local wifi local reloadSilent +local MOD_ABBR = "NTCF" + M.WWW_CAPTIVE_PATH = '/usr/share/lua/wifibox/www' M.WWW_CAPTIVE_INDICATOR = '/www/.wifibox-inplace' M.WWW_RENAME_NAME = '/www-regular' @@ -62,10 +64,10 @@ function M.switchConfiguration(components) for k,v in pairs(components) do local fname = k .. '_' .. v if type(reconf[fname]) == 'function' then - log:verbose("reconfiguring component '" .. k .. "' (" .. v .. ")") + log:verbose(MOD_ABBR, "reconfiguring component '" .. k .. "' (" .. v .. ")") reconf[fname](dirtyList) else - log:warning("unknown component or action '" .. fname .. "' skipped") + log:warning(MOD_ABBR, "unknown component or action '" .. fname .. "' skipped") end end @@ -79,12 +81,12 @@ function M.switchConfiguration(components) end function M.commitComponent(c) - log:info("committing component '" .. c .. "'") + log:info(MOD_ABBR, "committing component '" .. c .. "'") uci:commit(c) end function M.reloadComponent(c, silent) - log:info("reloading component '" .. c .. "'") + log:info(MOD_ABBR, "reloading component '" .. c .. "'") local command = 'reload' local cmd = '/etc/init.d/' .. c .. ' '..command if silent ~= nil and silent then @@ -92,7 +94,7 @@ function M.reloadComponent(c, silent) os.execute(cmd) else rv = utils.captureCommandOutput(cmd) - log:verbose(" result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv)) + log:verbose(MOD_ABBR, " result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv)) end end @@ -147,7 +149,7 @@ function reconf.apnet_rm(dirtyList) uci:foreach('wireless', 'wifi-iface', function(s) if s.ssid == wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) then sname = s['.name']; return false end end) - if sname == nil then return log:info("AP network configuration does not exist, nothing to remove") end + if sname == nil then return log:info(MOD_ABBR, "AP network configuration does not exist, nothing to remove") end uci:delete('wireless', sname) reloadBit(dirtyList, 'network'); commitBit(dirtyList, 'wireless') end @@ -212,15 +214,15 @@ end function reconf.dnsredir_add(dirtyList) local redirText = '/#/' .. settings.get('network.ap.address') local sname = utils.getUciSectionName('dhcp', 'dnsmasq') - if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end - if uci:get('dhcp', sname, 'address') ~= nil then return log:verbose("DNS address redirection already in place, not re-adding", false) end + if sname == nil then return log:error(MOD_ABBR, "dhcp config does not contain a dnsmasq section") end + if uci:get('dhcp', sname, 'address') ~= nil then return log:verbose(MOD_ABBR, "DNS address redirection already in place, not re-adding", false) end uci:set('dhcp', sname, 'address', {redirText}) commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq') end function reconf.dnsredir_rm(dirtyList) local sname = utils.getUciSectionName('dhcp', 'dnsmasq') - if sname == nil then return log:error("dhcp config does not contain a dnsmasq section") end + if sname == nil then return log:error(MOD_ABBR, "dhcp config does not contain a dnsmasq section") end uci:delete('dhcp', sname, 'address') commitBit(dirtyList, 'dhcp'); reloadBit(dirtyList, 'dnsmasq') @@ -230,21 +232,21 @@ end --TODO: handle os.rename() return values (nil+msg on error) function reconf.wwwcaptive_add(dirtyList) if utils.exists(M.WWW_CAPTIVE_INDICATOR) then - return log:verbose("WWW captive directory already in place, not redoing", false) + return log:verbose(MOD_ABBR, "WWW captive directory already in place, not redoing", false) end local rv,reason = os.rename('/www', M.WWW_RENAME_NAME) if rv == true then utils.symlink(M.WWW_CAPTIVE_PATH, '/www') return true else - return log:error("Could not rename /www to " .. M.WWW_RENAME_NAME .. "(" .. reason .. ")") + return log:error(MOD_ABBR, "Could not rename /www to " .. M.WWW_RENAME_NAME .. "(" .. reason .. ")") end end function reconf.wwwcaptive_rm(dirtyList) - if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:verbose("WWW captive directory not in place, not undoing", false) end + if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:verbose(MOD_ABBR, "WWW captive directory not in place, not undoing", false) end os.remove('/www') if os.rename(M.WWW_RENAME_NAME, '/www') ~= true then - return log:error("Could not rename " .. M.WWW_RENAME_NAME .. " to /www") + return log:error(MOD_ABBR, "Could not rename " .. M.WWW_RENAME_NAME .. " to /www") end return true end @@ -286,21 +288,21 @@ function M.setupAccessPoint(ssid) M.setStatus(M.CREATED,"Access point created"); local ds = wifi.getDeviceState() - --log:info(" network/status: ") - log:info(" ssid: ".. utils.dump(ds.ssid)) - --[[log:info(" bssid: ".. utils.dump(ds.bssid)) - log:info(" channel: ".. utils.dump(ds.channel)) - log:info(" mode: ".. utils.dump(ds.mode)) - log:info(" encryption: ".. utils.dump(ds.encryption)) - log:info(" quality: ".. utils.dump(ds.quality)) - log:info(" quality_max: ".. utils.dump(ds.quality_max)) - log:info(" txpower: ".. utils.dump(ds.txpower)) - log:info(" signal: ".. utils.dump(ds.signal)) - log:info(" noise: ".. utils.dump(ds.noise)) - log:info(" raw: ".. utils.dump(ds)) + --log:info(MOD_ABBR, " network/status: ") + log:info(MOD_ABBR, " ssid: ".. utils.dump(ds.ssid)) + --[[log:info(MOD_ABBR, " bssid: ".. utils.dump(ds.bssid)) + log:info(MOD_ABBR, " channel: ".. utils.dump(ds.channel)) + log:info(MOD_ABBR, " mode: ".. utils.dump(ds.mode)) + log:info(MOD_ABBR, " encryption: ".. utils.dump(ds.encryption)) + log:info(MOD_ABBR, " quality: ".. utils.dump(ds.quality)) + log:info(MOD_ABBR, " quality_max: ".. utils.dump(ds.quality_max)) + log:info(MOD_ABBR, " txpower: ".. utils.dump(ds.txpower)) + log:info(MOD_ABBR, " signal: ".. utils.dump(ds.signal)) + log:info(MOD_ABBR, " noise: ".. utils.dump(ds.noise)) + log:info(MOD_ABBR, " raw: ".. utils.dump(ds)) local localip = wifi.getLocalIP() - log:info(" localip: "..utils.dump(localip))]]-- + log:info(MOD_ABBR, " localip: "..utils.dump(localip))]]-- return true end @@ -311,13 +313,13 @@ end -- @tparam string ssid The SSID to use for the access point. -- @return True on success or nil+msg on error. function M.enableAccessPoint(ssid) - log:verbose("enableAccessPoint ssid: ".. utils.dump(ssid)) + log:verbose(MOD_ABBR, "enableAccessPoint ssid: ".. utils.dump(ssid)) M.switchConfiguration{apnet="add_noreload"} wifi.activateConfig(ssid) local ds = wifi.getDeviceState() - log:verbose(" ssid: ".. utils.dump(ds.ssid)) + log:verbose(MOD_ABBR, " ssid: ".. utils.dump(ds.ssid)) return true end @@ -330,7 +332,7 @@ end -- @tparam boolean recreate If true, a new UCI configuration based on scan data will always be created, otherwise an attempt will be made to use an existing configuration. -- @return True on success or nil+msg on error. function M.associateSsid(ssid, passphrase, recreate) - log:info("netconfig:associateSsid: "..(ssid or "")..", "..(recreate or "")) + log:info(MOD_ABBR, "netconfig:associateSsid: "..(ssid or "")..", "..(recreate or "")) M.setStatus(M.CONNECTING,"Connecting..."); -- see if previously configured network for given ssid exists @@ -374,7 +376,7 @@ function M.associateSsid(ssid, passphrase, recreate) local nextAttemptTime = os.time() while true do if os.time() > nextAttemptTime then - log:verbose("associated check "..utils.dump(attempt).."/"..utils.dump(maxAttempts)) + log:verbose(MOD_ABBR, "associated check "..utils.dump(attempt).."/"..utils.dump(maxAttempts)) if wifi.getLocalIP() ~= nil and wifi.getDeviceState().ssid == ssid then break else @@ -394,9 +396,9 @@ function M.associateSsid(ssid, passphrase, recreate) -- signin to connect.doodle3d.com local success, output = signin.signin() if success then - log:info("Signed in") + log:info(MOD_ABBR, "Signed in") else - log:info("Signing in failed") + log:info(MOD_ABBR, "Signing in failed") end -- report we are connected after signin attempt @@ -417,24 +419,24 @@ function M.disassociate() end function M.getStatus() - log:info("network:getStatus") + log:info(MOD_ABBR, "network:getStatus") local file, error = io.open('/tmp/networkstatus.txt','r') if file == nil then - --log:error("Util:Access:Can't read controller file. Error: "..error) + --log:error(MOD_ABBR, "Util:Access:Can't read controller file. Error: "..error) return "","" else local status = file:read('*a') - --log:info(" status: "..utils.dump(status)) + --log:info(MOD_ABBR, " status: "..utils.dump(status)) file:close() local code, msg = string.match(status, '([^|]+)|+(.*)') - --log:info(" code: "..utils.dump(code)) - --log:info(" msg: "..utils.dump(msg)) + --log:info(MOD_ABBR, " code: "..utils.dump(code)) + --log:info(MOD_ABBR, " msg: "..utils.dump(msg)) return code,msg end end function M.setStatus(code,msg) - log:info("network:setStatus: "..code.." | "..msg) + log:info(MOD_ABBR, "network:setStatus: "..code.." | "..msg) local file = io.open('/tmp/networkstatus.txt','w') file:write(code.."|"..msg) file:flush() diff --git a/src/network/signin.lua b/src/network/signin.lua index 3ad9fe2..6d8a8cf 100644 --- a/src/network/signin.lua +++ b/src/network/signin.lua @@ -20,6 +20,7 @@ local status = require('util.status') local M = {} local STATUS_FILE = "signinstatus" +local MOD_ABBR = "NTSI" local IDLE_STATUS = 1 local SIGNING_IN_STATUS = 2 @@ -28,14 +29,14 @@ local SIGNING_IN_STATUS = 2 -- function M.signin() - --log:verbose("signin:signin"); + --log:verbose(MOD_ABBR, "signin:signin"); local code, msg = M.getStatus() - --log:verbose(" status: "..utils.dump(code).." "..utils.dump(msg)); + --log:verbose(MOD_ABBR, " status: "..utils.dump(code).." "..utils.dump(msg)); -- if we are already signin in, skip if(code == SIGNING_IN_STATUS) then - log:verbose(" skipping signin") + log:verbose(MOD_ABBR, " skipping signin") return end @@ -53,10 +54,10 @@ function M.signin() local signinResponse = "" while true do if os.time() > nextAttemptTime then - log:verbose("signin attempt "..utils.dump(attempt).."/"..utils.dump(maxAttempts)) + log:verbose(MOD_ABBR, "signin attempt "..utils.dump(attempt).."/"..utils.dump(maxAttempts)) local signedin = false local localip = wifi.getLocalIP(); - --log:verbose(" localip: "..utils.dump(localip)) + --log:verbose(MOD_ABBR, " localip: "..utils.dump(localip)) if localip ~= nil then local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid')) @@ -64,16 +65,16 @@ function M.signin() local cmd = "wget -q -T 2 -t 1 -O - "..baseurl.."?wifiboxid="..wifiboxid.."\\&localip="..localip; signinResponse = utils.captureCommandOutput(cmd); - log:verbose(" signin response: \n"..utils.dump(signinResponse)) + log:verbose(MOD_ABBR, " signin response: \n"..utils.dump(signinResponse)) local success = signinResponse:match('"status":"success"') - log:verbose(" success: "..utils.dump(success)) + log:verbose(MOD_ABBR, " success: "..utils.dump(success)) if success ~= nil then signedin = true else - log:warning("signin failed request failed (response: "..utils.dump(signinResponse)..")") + log:warning(MOD_ABBR, "signin failed request failed (response: "..utils.dump(signinResponse)..")") end else - log:warning("signin failed no local ip found (attempt: "..utils.dump(attempt).."/"..utils.dump(maxAttempts)..")") + log:warning(MOD_ABBR, "signin failed no local ip found (attempt: "..utils.dump(attempt).."/"..utils.dump(maxAttempts)..")") end if signedin then @@ -100,7 +101,7 @@ function M.getStatus() end function M.setStatus(code,msg) - log:info("signin:setStatus: "..code.." | "..msg) + log:info(MOD_ABBR, "signin:setStatus: "..code.." | "..msg) status.set(STATUS_FILE,code,msg); end diff --git a/src/network/wlanconfig.lua b/src/network/wlanconfig.lua index 1b149c8..0a63573 100644 --- a/src/network/wlanconfig.lua +++ b/src/network/wlanconfig.lua @@ -13,6 +13,8 @@ local iwinfo = require('iwinfo') local M = {} +local MOD_ABBR = "NTWL" + -- NOTE: fallback device 'radio0' is required because sometimes the wlan0 device disappears M.DFL_DEVICE = 'wlan0' M.DFL_DEVICE_FALLBACK = 'radio0' @@ -75,7 +77,7 @@ function M.init(device) deviceName = M.DFL_DEVICE_FALLBACK deviceApi = iwinfo.type(deviceName) - log:info("wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'") + log:info(MOD_ABBR, "wireless device '" .. devInitial .. "' not found, trying fallback '" .. deviceName .. "'") if not deviceApi then return false, "No such wireless device: '" .. devInitial .. "' (and fallback '" .. deviceName .. "' does not exist either)" @@ -126,7 +128,7 @@ end --returns the wireless local ip address function M.getLocalIP() local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0"); - --log:verbose(" ifconfig: \n"..utils.dump(ifconfig)); + --log:verbose(MOD_ABBR, " ifconfig: \n"..utils.dump(ifconfig)); local localip = ifconfig:match('inet addr:([%d%.]+)') return localip @@ -187,12 +189,12 @@ end --- Activate wireless section for given SSID and disable all others -- @param ssid SSID of config to enable, or nil to disable all network configs function M.activateConfig(ssid) - --log:info("wlanconfig.activateConfig: "..ssid); + --log:info(MOD_ABBR, "wlanconfig.activateConfig: "..ssid); -- make sure only one is enabled uci:foreach('wireless', 'wifi-iface', function(s) local disabled = s.ssid ~= ssid and '1' or '0' - --log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled)) + --log:info(MOD_ABBR, " "..utils.dump(s.ssid).." disable: "..utils.dump(disabled)) uci:set('wireless', s['.name'], 'disabled', disabled) end) @@ -210,10 +212,10 @@ function M.activateConfig(ssid) return false end end) - --[[log:info(" result:"); + --[[log:info(MOD_ABBR, " result:"); uci:foreach('wireless', 'wifi-iface', function(s) local disabled = s.ssid ~= ssid and '1' or '0' - log:info(" "..utils.dump(s.ssid).." disable: "..utils.dump(disabled)) + log:info(MOD_ABBR, " "..utils.dump(s.ssid).." disable: "..utils.dump(disabled)) end)]]-- uci:commit('wireless') @@ -242,7 +244,7 @@ function M.createConfigFromScanInfo(info, passphrase, disabled) uci:foreach('wireless', 'wifi-iface', function(s) --if s.bssid == info.bssid then if s.ssid == info.ssid then - log:verbose("removing old wireless config for net '" .. s.ssid .. "'") + log:verbose(MOD_ABBR, "removing old wireless config for net '" .. s.ssid .. "'") uci:delete('wireless', s['.name']) -- return false --keep looking, just in case multiple entries with this bssid exist end diff --git a/src/rest/api/api_config.lua b/src/rest/api/api_config.lua index 7fcd9fe..9527919 100644 --- a/src/rest/api/api_config.lua +++ b/src/rest/api/api_config.lua @@ -15,6 +15,8 @@ local wifi = require('network.wlanconfig') local accessManager = require('util.access') local printerAPI = require('rest.api.api_printer') +local MOD_ABBR = "ACFG" + local M = { isApi = true } @@ -57,7 +59,7 @@ end -- returns substituted_wifiboxid (since version 0.10.2) -- returns substituted_ssid (since version 0.9.1) function M._global_POST(request, response) - --log:info("API:config:set") + --log:info(MOD_ABBR, "API:config:set") if not operationsAccessOrFail(request, response) then return end @@ -65,14 +67,14 @@ function M._global_POST(request, response) local validation = {} for k,v in pairs(request:getAll()) do - --log:info(" "..k..": "..v); + --log:info(MOD_ABBR, " "..k..": "..v); local r,m = settings.set(k, v, true) if r then validation[k] = "ok" elseif r == false then validation[k] = "could not save setting ('" .. m .. "')" - log:info(" m: "..utils.dump(m)) + log:info(MOD_ABBR, " m: "..utils.dump(m)) elseif r == nil then settings.commit() response:setError(m) @@ -84,7 +86,7 @@ function M._global_POST(request, response) local substitutedSsid = wifi.getSubstitutedSsid(settings.get('network.ap.ssid')) response:addData("substituted_ssid",substitutedSsid) - + local substitutedWiFiBoxID = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid')) response:addData("substituted_wifiboxid",substitutedWiFiBoxID) end @@ -109,12 +111,12 @@ end -- and printer.type is set to 'ultimaker' then -- only the printer.startcode under the ultimaker subsection is removed. function M.reset_POST(request, response) - --log:info("API:reset"); + --log:info(MOD_ABBR, "API:reset"); if not operationsAccessOrFail(request, response) then return end response:setSuccess() for k,v in pairs(request:getAll()) do - --log:info(" "..k..": "..v); + --log:info(MOD_ABBR, " "..k..": "..v); local r,m = settings.reset(k); if r ~= nil then response:addData(k, "ok") diff --git a/src/rest/api/api_info.lua b/src/rest/api/api_info.lua index 729d4a6..947a996 100644 --- a/src/rest/api/api_info.lua +++ b/src/rest/api/api_info.lua @@ -21,6 +21,7 @@ local LOG_COLLECT_DIRNAME = 'wifibox-logs' local LOG_COLLECT_DIR = TMP_DIR .. '/' .. LOG_COLLECT_DIRNAME local WIFIBOX_LOG_FILENAME = 'wifibox.log' local WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_LOG_FILENAME +local MOD_ABBR = "AINF" local SYSLOG_FILENAME = 'syslog' local PROCESS_LIST_FILENAME = 'processes' @@ -50,10 +51,10 @@ local M = { -- returns wifiboxid (since version 0.10.2) function M._global(request, response) response:setSuccess() - + local wifiboxid = wifi.getSubstitutedSsid(settings.get('network.cl.wifiboxid')) response:addData('wifiboxid', wifiboxid) - + end -- TODO: redirect stdout+stderr; handle errors @@ -147,12 +148,12 @@ function M.logfiles(request, response) end function M.access(request, response) - --log:info(" remoteAddress: |"..utils.dump(request.remoteAddress).."|"); - --log:info(" controller: |"..utils.dump(accessManager.getController()).."|"); + --log:info(MOD_ABBR, " remoteAddress: |"..utils.dump(request.remoteAddress).."|"); + --log:info(MOD_ABBR, " controller: |"..utils.dump(accessManager.getController()).."|"); local hasControl = accessManager.hasControl(request.remoteAddress) - -- if hasControl then log:info(" hasControl: true") - -- else log:info(" hasControl: false") end + -- if hasControl then log:info(MOD_ABBR, " hasControl: true") + -- else log:info(MOD_ABBR, " hasControl: false") end response:setSuccess() response:addData('has_control', hasControl) diff --git a/src/rest/api/api_network.lua b/src/rest/api/api_network.lua index 020176a..4e234bc 100644 --- a/src/rest/api/api_network.lua +++ b/src/rest/api/api_network.lua @@ -16,6 +16,8 @@ local signin = require('network.signin') local accessManager = require('util.access') local printerAPI = require('rest.api.api_printer') +local MOD_ABBR = "ANET" + local M = { isApi = true } @@ -149,9 +151,9 @@ function M.associate_POST(request, response) local rv,msg = netconf.associateSsid(argSsid, argPhrase, argRecreate) if rv then - log:info("associated to wifi: "..utils.dump(argSsid)) + log:info(MOD_ABBR, "associated to wifi: "..utils.dump(argSsid)) else - log:info("failed to associate to wifi: "..utils.dump(argSsid).." ("..utils.dump(msg)..")") + log:info(MOD_ABBR, "failed to associate to wifi: "..utils.dump(argSsid).." ("..utils.dump(msg)..")") end end @@ -201,14 +203,14 @@ function M.remove_POST(request, response) end function M.signin(request, response) - log:info("API:Network:signin") + log:info(MOD_ABBR, "API:Network:signin") local success, output = signin.signin() if success then - log:info("API:Network:signed in") + log:info(MOD_ABBR, "API:Network:signed in") response:setSuccess("API:Network:signed in") response:addData("response", output) else - log:info("API:Network:Signing in failed") + log:info(MOD_ABBR, "API:Network:Signing in failed") response:setError("Signing in failed") end end diff --git a/src/rest/api/api_printer.lua b/src/rest/api/api_printer.lua index 9cd44bc..c90c542 100644 --- a/src/rest/api/api_printer.lua +++ b/src/rest/api/api_printer.lua @@ -14,6 +14,8 @@ local printDriver = require('print3d') local printerUtils = require('util.printer') local accessManager = require('util.access') +local MOD_ABBR = "APRN" + local M = { isApi = true } @@ -68,7 +70,7 @@ function M.progress(request, response) return true; end --- NOTE: onlyReturnState is optional and prevents response from being modified +-- NOTE: onlyReturnState is optional and prevents response from being modified, used when calling from within other api call function M.state(request, response, onlyReturnState) local argId = request:get("id") if not onlyReturnState then response:addData('id', argId) end @@ -136,7 +138,7 @@ end function M.stop_POST(request, response) - log:info("API:printer/stop") + log:info(MOD_ABBR, "API:printer/stop") if not accessManager.hasControl(request.remoteAddress) then response:setFail("No control access") @@ -159,6 +161,8 @@ function M.stop_POST(request, response) end end +--requires: gcode(string) (the gcode to be appended) +--accepts: id(string) (the printer ID to append to) --accepts: first(bool) (chunks will be concatenated but output file will be cleared first if this argument is true) --accepts: start(bool) (only when this argument is true will printing be started) function M.print_POST(request, response) @@ -172,7 +176,7 @@ function M.print_POST(request, response) hasControl = true end - log:info(" hasControl: "..utils.dump(hasControl)) + log:info(MOD_ABBR, " hasControl: "..utils.dump(hasControl)) if not hasControl then response:setFail("No control access") return @@ -194,7 +198,7 @@ function M.print_POST(request, response) end if argIsFirst == true then - log:verbose("clearing all gcode for " .. printer:getId()) + log:verbose(MOD_ABBR, "clearing all gcode for " .. printer:getId()) response:addData('gcode_clear',true) local rv,msg = printer:clearGcode() diff --git a/src/rest/api/api_sketch.lua b/src/rest/api/api_sketch.lua index 06375d9..ae71ce2 100644 --- a/src/rest/api/api_sketch.lua +++ b/src/rest/api/api_sketch.lua @@ -16,6 +16,8 @@ local lfs = require('lfs') local log = require('util.logger') local utils = require('util.utils') +local MOD_ABBR = "ASKE" + local M = { isApi = true, SKETCH_DIR = '/root/sketches', @@ -29,7 +31,7 @@ local SKETCH_FILE_EXTENSION = 'svg' -- creates sketch directory, and sets response to error state on failure local function createSketchDirectory() if os.execute('mkdir -p ' .. M.SKETCH_DIR) ~= 0 then - log:error("Error: could not create sketch directory '" .. M.SKETCH_DIR .. "'") + log:error(MOD_ABBR, "Error: could not create sketch directory '" .. M.SKETCH_DIR .. "'") response:setError("could not create sketch directory") return false end @@ -133,7 +135,7 @@ function M._global_POST(request, response) local sketchIdx = listSize > 0 and sketches[listSize] + 1 or 1 local sketchFile = M.SKETCH_DIR .. '/' .. constructSketchFilename(sketchIdx) - log:verbose("saving sketch #" .. sketchIdx .. " (" .. argData:len() .. " bytes)") + log:verbose(MOD_ABBR, "saving sketch #" .. sketchIdx .. " (" .. argData:len() .. " bytes)") local saveFile,msg = io.open(sketchFile, 'w') if not saveFile then diff --git a/src/rest/api/api_update.lua b/src/rest/api/api_update.lua index bae97a0..61386e4 100644 --- a/src/rest/api/api_update.lua +++ b/src/rest/api/api_update.lua @@ -10,6 +10,8 @@ local wifi = require('network.wlanconfig') local netconf = require('network.netconfig') local settings = require('util.settings') +local MOD_ABBR = "AUPD" + -- NOTE: the updater module 'detects' command-line invocation by existence of 'arg', so we have to make sure it is not defined. argStash = arg arg = nil @@ -158,7 +160,7 @@ end function M.install_POST(request, response) local argVersion = request:get("version") local argNoRetain = request:get("no_retain") - log:info("API:update/install (noRetain: "..utils.dump(argNoRetain)..")") + log:info(MOD_ABBR, "API:update/install (noRetain: "..utils.dump(argNoRetain)..")") local noRetain = argNoRetain == 'true' if not operationsAccessOrFail(request, response) then return end diff --git a/src/rest/response.lua b/src/rest/response.lua index 580d2b7..159e825 100644 --- a/src/rest/response.lua +++ b/src/rest/response.lua @@ -20,6 +20,7 @@ local M = {} M.__index = M local REQUEST_ID_ARGUMENT = 'rq_id' +local MOD_ABBR = "HRSP" M.httpStatusCode, M.httpStatusText, M.contentType = nil, nil, nil M.binaryData, M.binarySavename = nil, nil @@ -131,7 +132,7 @@ end --- Call all function on the post-response queue, see @{M:addPostResponseFunction} for details and a side-note. function M:executePostResponseQueue() - --log:info("Response:executePostResponseQueue: " .. utils.dump(self.postResponseQueue)) + --log:info(MOD_ABBR, "Response:executePostResponseQueue: " .. utils.dump(self.postResponseQueue)) for i,fn in ipairs(self.postResponseQueue) do fn() end end @@ -169,7 +170,7 @@ function M:send() end if self.body.status ~= "success" then - log:verbose("Response:"..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")") + log:verbose(MOD_ABBR, "Response:"..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")") end end diff --git a/src/script/d3d-updater.lua b/src/script/d3d-updater.lua index 9cdb0ff..7bb678d 100644 --- a/src/script/d3d-updater.lua +++ b/src/script/d3d-updater.lua @@ -24,6 +24,8 @@ -- note: take care not to print any text in module functions, as this breaks http responses -- change representation of sysupgrade/factory info in versionInfo? (and also in image index?) <- create api call to get all info on all versions? +local MOD_ABBR = "UPDA" + local M = {} --- Possible states the updater can be in, they are stored in @{STATE_FILE}. @@ -82,8 +84,8 @@ local baseUrl = M.DEFAULT_BASE_URL -- default, can be overwritten by M.setBaseUr -- @string msg The message to log. local function P(lvl, msg) if log then - if lvl == -1 then log:verbose(msg) - elseif lvl == 0 or lvl == 1 then log:info(msg) + if lvl == -1 then log:verbose(MOD_ABBR, msg) + elseif lvl == 0 or lvl == 1 then log:info(MOD_ABBR, msg) end else if (-lvl <= verbosity) then print(msg) end @@ -99,7 +101,7 @@ local function D(msg) P(-1, (log and msg or "(DBG) " .. msg)) end -- Messages will be written to [stderr](http://www.cplusplus.com/reference/cstdio/stderr/), or logged using the logger set with @{setLogger}. -- @string msg The message to log. local function E(msg) - if log then log:error(msg) + if log then log:error(MOD_ABBR, msg) else io.stderr:write(msg .. '\n') end end @@ -792,7 +794,7 @@ end -- @treturn bool|nil True on success (with the 'exception' as noted above) or nil on error. -- @treturn ?string|number (optional) Descriptive message or sysupgrade exit status on error. function M.flashImageVersion(versionEntry, noRetain, devType, isFactory) - if log then log:info("flashImageVersion") end + if log then log:info(MOD_ABBR, "flashImageVersion") end local imgName = M.constructImageFilename(versionEntry.version, devType, isFactory) local cmd = noRetain and 'sysupgrade -n ' or 'sysupgrade ' cmd = cmd .. cachePath .. '/' .. imgName diff --git a/src/util/access.lua b/src/util/access.lua index b7da5c6..cf2ac64 100644 --- a/src/util/access.lua +++ b/src/util/access.lua @@ -10,38 +10,40 @@ local log = require('util.logger') local utils = require('util.utils') local printerUtils = require('util.printer') +local MOD_ABBR = "UACS" + local M = {} function M.hasControl(ip) local controllerIP = M.getController() - + -- no controller stored? we have control if controllerIP == "" then return true end; - + -- controller stored is same as our (requesting) ip? we have control if(controllerIP == ip) then return true end; - + -- no printer connected? we have control local printer,msg = printerUtils.createPrinterOrFail() - if not printer or not printer:hasSocket() then + if not printer or not printer:hasSocket() then M.setController("") -- clear the controller return true end - + -- printer is idle (done printing)? we have control local state = printer:getState() if state == "idle" then -- TODO: define in constants somewhere M.setController("") -- clear controller return true end - + return false end function M.getController() local file, error = io.open('/tmp/controller.txt','r') if file == nil then - --log:error("Util:Access:Can't read controller file. Error: "..error) + --log:error(MOD_ABBR, "Util:Access:Can't read controller file. Error: "..error) return "" else controllerIP = file:read('*a') diff --git a/src/util/logger.lua b/src/util/logger.lua index 39ac173..3ce3af4 100644 --- a/src/util/logger.lua +++ b/src/util/logger.lua @@ -32,7 +32,7 @@ for i,v in ipairs(M.LEVEL) do end -local function log(level, msg, verboseFmt) +local function log(level, module, msg, verboseFmt) if level <= logLevel then local now = os.date('%m-%d %H:%M:%S') local i = debug.getinfo(3) --the stack frame just above the logger call @@ -41,9 +41,10 @@ local function log(level, msg, verboseFmt) local name = i.name or "(nil)" local vVal = 'nil' local m = (type(msg) == 'string') and msg or utils.dump(msg) + if module == nil then module = "LUA " end - if v then logStream:write(now .. " (" .. M.LEVEL[level] .. ") " .. m .. " [" .. name .. "@" .. i.short_src .. ":" .. i.linedefined .. "]\n") - else logStream:write(now .. " (" .. M.LEVEL[level] .. ") " .. m .. "\n") end + if v then logStream:write(now .. " [" .. module .. "] (" .. M.LEVEL[level] .. "): " .. m .. " [" .. name .. "@" .. i.short_src .. ":" .. i.linedefined .. "]\n") + else logStream:write(now .. " [" .. module .. "] (" .. M.LEVEL[level] .. "): " .. m .. "\n") end logStream:flush() end @@ -52,11 +53,11 @@ end --- Initializes the logger. -- @tparam @{util.logger.LEVEL} level Minimum level of messages to log. --- @tparam bool verbose Write verbose log messages (include file/line inforomation). +-- @tparam bool verbose Write verbose log messages (include file/line information). function M:init(level, verboseFmt) logLevel = level or M.LEVEL.warning logVerboseFmt = verboseFmt or false - logStream = stream or io.stdout + --logStream = stream or io.stdout end function M:setLevel(level, verboseFmt) @@ -73,10 +74,14 @@ function M:getLevel() return logLevel, logVerboseFmt end -function M:error(msg, verboseFmt) log(M.LEVEL.error, msg, verboseFmt); return false end -function M:warning(msg, verboseFmt) log(M.LEVEL.warning, msg, verboseFmt); return true end -function M:info(msg, verboseFmt) log(M.LEVEL.info, msg, verboseFmt); return true end -function M:verbose(msg, verboseFmt) log(M.LEVEL.verbose, msg, verboseFmt); return true end -function M:bulk(msg, verboseFmt) log(M.LEVEL.bulk, msg, verboseFmt); return true end +function M:getStream() + return logStream +end + +function M:error(module, msg, verboseFmt) log(M.LEVEL.error, module, msg, verboseFmt); return false end +function M:warning(module, msg, verboseFmt) log(M.LEVEL.warning, module, msg, verboseFmt); return true end +function M:info(module, msg, verboseFmt) log(M.LEVEL.info, module, msg, verboseFmt); return true end +function M:verbose(module, msg, verboseFmt) log(M.LEVEL.verbose, module, msg, verboseFmt); return true end +function M:bulk(module, msg, verboseFmt) log(M.LEVEL.bulk, module, msg, verboseFmt); return true end return M diff --git a/src/util/printer.lua b/src/util/printer.lua index 13ec827..a61781f 100644 --- a/src/util/printer.lua +++ b/src/util/printer.lua @@ -10,6 +10,8 @@ local log = require('util.logger') local utils = require('util.utils') local printDriver = require('print3d') +local MOD_ABBR = "UPRN" + local SUPPORTED_PRINTERS = { rigidbot = "Rigidbot", ultimaker = "Ultimaker", @@ -81,8 +83,8 @@ end --returns a printer instance or nil (and sets error state on response in the latter case) function M.createPrinterOrFail(deviceId, response) - --log:verbose("API:printer:createPrinterOrFail: "..utils.dump(deviceId)) - local msg,printer = nil, nil + --log:verbose(MOD_ABBR, "API:printer:createPrinterOrFail: "..utils.dump(deviceId)) + local rv,msg,printer = nil, nil, nil if deviceId == nil or deviceId == "" then printer,msg = printDriver.getPrinter() @@ -98,7 +100,17 @@ function M.createPrinterOrFail(deviceId, response) return nil end - printer:setLocalLogLevel(log:getLevel()) + -- only log these log setup errors, do not let them prevent further request handling + + rv,msg = printer:setLocalLogStream(log:getStream()) + if not rv then + log:error(MOD_ABBR, "could not set log stream in Lua binding (" .. msg .. ")") + end + + rv,msg = printer:setLocalLogLevel(log:getLevel()) + if not rv then + log:error(MOD_ABBR, "could not set log level '" .. log:getLevel() .. "' in Lua binding (" .. msg .. ")") + end return printer end diff --git a/src/util/settings.lua b/src/util/settings.lua index a01693e..b9d14e3 100644 --- a/src/util/settings.lua +++ b/src/util/settings.lua @@ -19,6 +19,8 @@ local baseconfig = require('conf_defaults') local utils = require('util.utils') local log = require('util.logger') +local MOD_ABBR = "USET" + local M = {} --- UCI config name (i.e., file under `/etc/config`) @@ -159,7 +161,7 @@ end]]-- -- @return The associated value, beware (!) that this may be boolean false for keys of 'bool' type, or nil if the key could not be read because of a UCI error. -- @treturn string Message in case of error. function M.get(key) - --log:info("settings:get: "..utils.dump(key)) + --log:info(MOD_ABBR, "settings:get: "..utils.dump(key)) key = replaceDots(key) -- retrieve settings's base settings from conf_defaults.lua @@ -177,7 +179,7 @@ function M.get(key) local uciV,msg = uci:get(UCI_CONFIG_NAME, section, key) if not uciV and msg ~= nil then local errorMSG = "Issue reading setting '"..utils.dump(key).."': "..utils.dump(msg); - log:info(errorMSG) + log:info(MOD_ABBR, errorMSG) return nil, errorMSG; end @@ -244,21 +246,21 @@ end -- @treturn bool|nil True if everything went well, false if validation error, nil in case of error. -- @treturn ?string Error message in case first return value is nil (invalid key). function M.set(key, value, noCommit) - log:info("settings:set: "..utils.dump(key).." to: "..utils.dump(value)) + log:info(MOD_ABBR, "settings:set: "..utils.dump(key).." to: "..utils.dump(value)) key = replaceDots(key) local r = utils.create(UCI_CONFIG_FILE) local rv, msg = uci:set(UCI_CONFIG_NAME, UCI_CONFIG_SECTION, UCI_CONFIG_TYPE) if not rv and msg ~= nil then local errorMSG = "Issue creating section '"..utils.dump(UCI_CONFIG_SECTION).."': "..utils.dump(msg); - log:info(errorMSG) + log:info(MOD_ABBR, errorMSG) return nil, errorMSG; end local base = getBaseKeyTable(key) if not base then return false,ERR_NO_SUCH_KEY end - --log:info(" base.type: "..utils.dump(base.type)) + --log:info(MOD_ABBR, " base.type: "..utils.dump(base.type)) if base.type == 'bool' then if value ~= "" then value = utils.toboolean(value) @@ -271,7 +273,7 @@ function M.set(key, value, noCommit) return false,"Value isn't a valid int or float" end end - + local valid,m = isValid(value, base) if not valid then return false,m @@ -283,7 +285,7 @@ function M.set(key, value, noCommit) local rv, msg = uci:set(UCI_CONFIG_NAME, section, UCI_CONFIG_TYPE) if not rv and msg ~= nil then local errorMSG = "Issue getting subsection '"..utils.dump(base.subSection).."': "..utils.dump(msg); - log:info(errorMSG) + log:info(MOD_ABBR, errorMSG) return nil, errorMSG; end end @@ -292,14 +294,14 @@ function M.set(key, value, noCommit) local rv, msg = uci:set(UCI_CONFIG_NAME, section, key, toUciValue(value, base.type)) if not rv and msg ~= nil then local errorMSG = "Issue setting setting '"..utils.dump(key).."' in section '"..utils.dump(section).."': "..utils.dump(msg); - log:info(errorMSG) + log:info(MOD_ABBR, errorMSG) return nil, errorMSG; end else local rv, msg = uci:delete(UCI_CONFIG_NAME, section, key) if not rv and msg ~= nil then local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..utils.dump(section).."': "..utils.dump(msg); - log:info(errorMSG) + log:info(MOD_ABBR, errorMSG) return nil, errorMSG; end end @@ -318,35 +320,35 @@ end -- @string key The key to set. -- @treturn bool|nil True if everything went well, nil in case of error. function M.resetAll() - log:info("settings:resetAll") + log:info(MOD_ABBR, "settings:resetAll") -- find all sections local allSections, msg = uci:get_all(UCI_CONFIG_NAME) if not allSections and msg ~= nil then local errorMSG = "Issue reading all settings: "..utils.dump(msg); - log:info(errorMSG) + log:info(MOD_ABBR, errorMSG) return nil, errorMSG; end - + -- delete all uci sections but system for key,value in pairs(allSections) do if key ~= "system" and not key:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway local rv, msg = uci:delete(UCI_CONFIG_NAME,key) if not rv and msg ~= nil then local errorMSG = "Issue deleting setting '"..utils.dump(key).."': "..utils.dump(msg); - log:info(errorMSG) + log:info(MOD_ABBR, errorMSG) return nil, errorMSG; end end end - + -- reset all to defaults for k,_ in pairs(baseconfig) do if not k:match('^[A-Z_]*$') then --TEMP: skip 'constants', which should be moved anyway M.reset(k,true) end end - + M.commit() return true end @@ -356,7 +358,7 @@ end -- @p[opt=nil] noCommit If true, do not commit the uci configuration; this is more efficient when resetting multiple values -- @treturn bool|nil True if everything went well, nil in case of error. function M.reset(key, noCommit) - log:info("settings:reset: "..utils.dump(key)) + log:info(MOD_ABBR, "settings:reset: "..utils.dump(key)) -- delete key = replaceDots(key) @@ -365,13 +367,13 @@ function M.reset(key, noCommit) local section = UCI_CONFIG_SECTION; if base.subSection ~= nil then section = M.get(base.subSection) - end + end local rv, msg = uci:delete(UCI_CONFIG_NAME, section, key) - -- we can't respond to errors in general here because when a key isn't found + -- we can't respond to errors in general here because when a key isn't found -- (which always happens when reset is used in resetall) it will also generate a error --if not rv and msg ~= nil then -- local errorMSG = "Issue deleting setting '"..utils.dump(key).."' in section '"..section.."': "..utils.dump(msg); - -- log:info(errorMSG) + -- log:info(MOD_ABBR, errorMSG) -- return nil, errorMSG; --end diff --git a/src/util/status.lua b/src/util/status.lua index 3f91736..6d38149 100644 --- a/src/util/status.lua +++ b/src/util/status.lua @@ -9,13 +9,15 @@ local log = require('util.logger') local utils = require('util.utils') +local MOD_ABBR = "USTS" + local M = {} local FOLDER = "/tmp/" local FILE_PREFIX = "d3d-" local FILE_EXTENSION = ".txt" -function getPath(fileName) +function getPath(fileName) return FOLDER..FILE_PREFIX..fileName..FILE_EXTENSION end @@ -23,7 +25,7 @@ function M.get(fileName) local path = getPath(fileName) local file, error = io.open(path,'r') if file == nil then - --log:error("Util:Access:Can't read controller file. Error: "..error) + --log:error(MOD_ABBR, "Util:Access:Can't read controller file. Error: "..error) return "","" else local status = file:read('*a') @@ -35,7 +37,7 @@ function M.get(fileName) end function M.set(fileName,code,msg) - --log:info("setStatus: "..code.." | "..msg) + --log:info(MOD_ABBR, "setStatus: "..code.." | "..msg) local path = getPath(fileName) local file = io.open(path,'w') file:write(code.."|"..msg)