0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-12-22 02:53:49 +01:00

Change levels and improve consistency in log statements.

This commit is contained in:
Wouter R 2014-05-12 12:22:16 +02:00
parent 5f59e5e2c9
commit 1439bd0434
8 changed files with 47 additions and 39 deletions

View File

@ -227,31 +227,32 @@ local function main(environment)
local version = updater.formatVersion(updater.getCurrentVersion());
log:info(MOD_ABBR, "Doodle3D version: "..util.dump(version))
log:info(MOD_ABBR, "running in autowifi mode")
log:info(MOD_ABBR, "Running in autowifi mode")
local rv,msg = setupAutoWifiMode()
if rv then
log:info(MOD_ABBR, "autowifi setup done (" .. msg .. ")")
log:info(MOD_ABBR, "Autowifi setup done (" .. msg .. ")")
else
log:error(MOD_ABBR, "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(MOD_ABBR, "running in signin mode")
log:info(MOD_ABBR, "Running in signin mode")
local ds = wifi.getDeviceState()
log:info(MOD_ABBR, " ds.mode: "..util.dump(ds.mode))
log:info(MOD_ABBR, " wifi deviceState.mode: "..util.dump(ds.mode))
if ds.mode == "sta" then
log:info(MOD_ABBR, " attempting signin")
local success,msg = Signin.signin()
if success then
log:info(MOD_ABBR, "Signin successful")
else
log:info(MOD_ABBR, "Signin failed: "..util.dump(msg))
log:warning(MOD_ABBR, "Signin failed: "..util.dump(msg))
end
end
elseif rq:getRequestMethod() ~= 'CMDLINE' or confDefaults.DEBUG_API then
-- log:info(MOD_ABBR, "received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll()))
-- Note: the commented log statement will print too many data if it's for instance dumping a gcode add request
--log:info(MOD_ABBR, "received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
-- .. "/" .. (rq:getRealApiFunctionName() or "<unknown>") .. " with arguments: " .. util.dump(rq:getAll()))
log:info(MOD_ABBR, "received request of type " .. rq:getRequestMethod() .. " for " .. (rq:getRequestedApiModule() or "<unknown>")
.. "/" .. (rq:getRealApiFunctionName() or "<unknown>"))
if rq:getRequestMethod() ~= 'CMDLINE' then
@ -287,7 +288,7 @@ function handle_request(env)
resp:setError("initialization failed" .. errSuffix)
resp:send()
log:error(MOD_ABBR, "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

View File

@ -64,7 +64,7 @@ function M.switchConfiguration(components)
for k,v in pairs(components) do
local fname = k .. '_' .. v
if type(reconf[fname]) == 'function' then
log:verbose(MOD_ABBR, "reconfiguring component '" .. k .. "' (" .. v .. ")")
log:info(MOD_ABBR, "reconfiguring component '" .. k .. "' (" .. v .. ")")
reconf[fname](dirtyList)
else
log:warning(MOD_ABBR, "unknown component or action '" .. fname .. "' skipped")
@ -94,7 +94,7 @@ function M.reloadComponent(c, silent)
os.execute(cmd)
else
rv = utils.captureCommandOutput(cmd)
log:verbose(MOD_ABBR, " result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
log:info(MOD_ABBR, " result reloading component '" .. c .. "' (cmd: '"..cmd.."'): \n"..utils.dump(rv))
end
end
@ -215,7 +215,7 @@ 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(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
if uci:get('dhcp', sname, 'address') ~= nil then return log:info(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')
@ -232,7 +232,7 @@ 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(MOD_ABBR, "WWW captive directory already in place, not redoing", false)
return log:info(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
@ -243,7 +243,7 @@ function reconf.wwwcaptive_add(dirtyList)
end
end
function reconf.wwwcaptive_rm(dirtyList)
if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:verbose(MOD_ABBR, "WWW captive directory not in place, not undoing", false) end
if not utils.exists(M.WWW_CAPTIVE_INDICATOR) then return log:info(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(MOD_ABBR, "Could not rename " .. M.WWW_RENAME_NAME .. " to /www")
@ -290,7 +290,8 @@ function M.setupAccessPoint(ssid)
local ds = wifi.getDeviceState()
--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, " 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))
@ -302,7 +303,8 @@ function M.setupAccessPoint(ssid)
log:info(MOD_ABBR, " raw: ".. utils.dump(ds))
local localip = wifi.getLocalIP()
log:info(MOD_ABBR, " localip: "..utils.dump(localip))]]--
log:info(MOD_ABBR, " localip: "..utils.dump(localip))
--]]
return true
end
@ -313,13 +315,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(MOD_ABBR, "enableAccessPoint ssid: ".. utils.dump(ssid))
log:info(MOD_ABBR, "enableAccessPoint ssid: ".. utils.dump(ssid))
M.switchConfiguration{apnet="add_noreload"}
wifi.activateConfig(ssid)
local ds = wifi.getDeviceState()
log:verbose(MOD_ABBR, " ssid: ".. utils.dump(ds.ssid))
log:info(MOD_ABBR, " deviceState.ssid: ".. utils.dump(ds.ssid))
return true
end
@ -392,6 +394,7 @@ function M.associateSsid(ssid, passphrase, recreate)
end
end
end
log:info(MOD_ABBR, "Network associated")
-- signin to connect.doodle3d.com
local success, output = signin.signin()
@ -426,11 +429,9 @@ function M.getStatus()
return "",""
else
local status = file:read('*a')
--log:info(MOD_ABBR, " status: "..utils.dump(status))
file:close()
local code, msg = string.match(status, '([^|]+)|+(.*)')
--log:info(MOD_ABBR, " code: "..utils.dump(code))
--log:info(MOD_ABBR, " msg: "..utils.dump(msg))
log:verbose(MOD_ABBR, " raw status: "..utils.dump(status).." (code: "..utils.dump(code)..", msg: "..utils.dump(msg)..")")
return code,msg
end
end

View File

@ -54,7 +54,7 @@ function M.signin()
local signinResponse = ""
while true do
if os.time() > nextAttemptTime then
log:verbose(MOD_ABBR, "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(MOD_ABBR, " localip: "..utils.dump(localip))
@ -71,10 +71,10 @@ function M.signin()
if success ~= nil then
signedin = true
else
log:warning(MOD_ABBR, "signin failed request failed (response: "..utils.dump(signinResponse)..")")
log:warning(MOD_ABBR, "signin failed, request failed (response: "..utils.dump(signinResponse)..")")
end
else
log:warning(MOD_ABBR, "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

View File

@ -128,7 +128,7 @@ end
--returns the wireless local ip address
function M.getLocalIP()
local ifconfig, rv = utils.captureCommandOutput("ifconfig wlan0");
--log:verbose(MOD_ABBR, " ifconfig: \n"..utils.dump(ifconfig));
log:bulk(MOD_ABBR, " ifconfig: \n"..utils.dump(ifconfig));
local localip = ifconfig:match('inet addr:([%d%.]+)')
return localip
@ -189,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(MOD_ABBR, "wlanconfig.activateConfig: "..ssid);
log:verbose(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(MOD_ABBR, " "..utils.dump(s.ssid).." disable: "..utils.dump(disabled))
log:verbose(MOD_ABBR, " ssid: "..utils.dump(s.ssid).." disabled: "..utils.dump(disabled))
uci:set('wireless', s['.name'], 'disabled', disabled)
end)
@ -212,11 +212,14 @@ function M.activateConfig(ssid)
return false
end
end)
--[[log:info(MOD_ABBR, " result:");
--[[
log:verbose(MOD_ABBR, " wifi reorder result:");
uci:foreach('wireless', 'wifi-iface', function(s)
local disabled = s.ssid ~= ssid and '1' or '0'
log:info(MOD_ABBR, " "..utils.dump(s.ssid).." disable: "..utils.dump(disabled))
end)]]--
log:verbose(MOD_ABBR, " ssid: "..utils.dump(s.ssid).." disabled: "..utils.dump(disabled))
end)
--]]
uci:commit('wireless')
end

View File

@ -59,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(MOD_ABBR, "API:config:set")
log:verbose(MOD_ABBR, "API:config(set)")
if not operationsAccessOrFail(request, response) then return end
@ -67,14 +67,14 @@ function M._global_POST(request, response)
local validation = {}
for k,v in pairs(request:getAll()) do
--log:info(MOD_ABBR, " "..k..": "..v);
log:verbose(MOD_ABBR, " about to set '"..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(MOD_ABBR, " m: "..utils.dump(m))
log:info(MOD_ABBR, " failed to set '"..k.."' ("..utils.dump(m)..")")
elseif r == nil then
settings.commit()
response:setError(m)
@ -111,7 +111,7 @@ 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(MOD_ABBR, "API:reset");
--log:verbose(MOD_ABBR, "API:config/reset")
if not operationsAccessOrFail(request, response) then return end
response:setSuccess()
@ -120,9 +120,11 @@ function M.reset_POST(request, response)
local r,m = settings.reset(k);
if r ~= nil then
response:addData(k, "ok")
log:verbose(MOD_ABBR, " reset " .. k)
else
response:addData(k, "could not reset key ('" .. m .. "')")
response:setError(m)
log:verbose(MOD_ABBR, " could not reset key " .. k .. "(" .. m .. ")")
return
end
end

View File

@ -203,14 +203,14 @@ function M.remove_POST(request, response)
end
function M.signin(request, response)
log:info(MOD_ABBR, "API:Network:signin")
log:info(MOD_ABBR, "API:network/signin")
local success, output = signin.signin()
if success then
log:info(MOD_ABBR, "API:Network:signed in")
log:info(MOD_ABBR, " signed in")
response:setSuccess("API:Network:signed in")
response:addData("response", output)
else
log:info(MOD_ABBR, "API:Network:Signing in failed")
log:info(MOD_ABBR, "signing in failed")
response:setError("Signing in failed")
end
end

View File

@ -166,6 +166,7 @@ end
--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)
log:info(MOD_ABBR, "API:printer/print")
local controllerIP = accessManager.getController()
local hasControl = false
@ -198,7 +199,7 @@ function M.print_POST(request, response)
end
if argIsFirst == true then
log:verbose(MOD_ABBR, "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()

View File

@ -31,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(MOD_ABBR, "Error: could not create sketch directory '" .. M.SKETCH_DIR .. "'")
log:error(MOD_ABBR, "could not create sketch directory '" .. M.SKETCH_DIR .. "'")
response:setError("could not create sketch directory")
return false
end