Wifibox stdout/stderr log file:

- rename 'wifibox.cgi-fallback.log' to 'wifibox.stdout.log'
- extend description of Lua debugging (and the fallback log)
- send fallback log along with info/logfiles request
This commit is contained in:
Wouter R 2016-02-23 16:18:42 +01:00
parent 97612c8a74
commit b4aa1a9746
4 changed files with 13 additions and 4 deletions

View File

@ -3,6 +3,7 @@ WiFi box OpenWRT firmware package
General documentation can be found on the wiki: <http://doodle3d.com/help/wiki>. Source code documentation can be generated, see below.
Documentation
-------------
@ -19,5 +20,8 @@ Syntax errors in Lua can lead to tricky issues since they might only surface whe
One countermeasure for this is to use [pcall](http://www.lua.org/pil/8.4.html) instead of regular calls in many cases. To let the error 'happen' (which in turn gives information in the form of stack traces), tell the code to use regular calls by setting 'M.DEBUG_PCALLS' to 'true' in `conf_defaults.lua`.
A second way of debugging is to take uhttpd out of the loop and invoke the Lua code from command-line. To do this, set 'M.DEBUG_API' to 'true' in `conf_defaults.lua`. Then invoke the API using the command `d3dapi p=/mod/func r=POST` where `p=` is followed by the API path and `r=` followed by either 'GET' or 'POST'.
Be aware though, that this script redirects output streams to a fallback log file where stack traces will end up, this file is `/tmp/wifibox.cgi-fallback.log`.
Additionally, when the pcall setting is not enough, a second way of debugging is to take uhttpd out of the loop and invoke the Lua code from command-line. To do this, set 'M.DEBUG_API' to 'true' in `conf_defaults.lua`. Then invoke the API using the command `d3dapi p=/mod/func r=POST` where `p=` is followed by the API path and `r=` followed by either 'GET' or 'POST'.
Note that because stack traces are sent to `stderr`, this script redirects output streams to a separate log file: `/tmp/wifibox.stdout.log`; apart from these traces, the file should not contain any data.
Finally, the `CGI` gateway of uhttpd also uses this script, so the API can also be used to obtain stack traces by calling it as `<wifibox-ip>/cgi-bin/d3dapi/<endpoint>` (note the extra `cgi-bin`).

View File

@ -36,7 +36,7 @@ M.DEBUG_PCALLS = false
--- This constant enables debugging of the REST API from the command-line by emulating GET/POST requests.
-- Specify the path and optionally the request method as follows: `d3dapi p=/mod/func r=POST`.
-- Note that the command-line script redirects the output streams to '/tmp/wifibox.cgi-fallback.log'
-- Note that the command-line script redirects the output streams to '/tmp/wifibox.stdout.log',
-- meaning that any stack traces can be found there.
M.DEBUG_API = true

View File

@ -21,6 +21,8 @@ local LOG_COLLECT_DIRNAME = 'wifibox-logs'
local LOG_COLLECT_DIR = TMP_DIR .. '/' .. LOG_COLLECT_DIRNAME
local DEFAULT_WIFIBOX_LOG_FILENAME = 'wifibox.log'
local DEFAULT_WIFIBOX_LOG_FILE = TMP_DIR .. '/' .. DEFAULT_WIFIBOX_LOG_FILENAME
local WIFIBOX_STDOUT_LOG_FILENAME = 'wifibox.stdout.log'
local WIFIBOX_STDOUT_LOG_FILE = TMP_DIR .. '/' .. WIFIBOX_STDOUT_LOG_FILENAME
local MOD_ABBR = "AINF"
local SYSLOG_FILENAME = 'syslog'
@ -73,6 +75,9 @@ function M.logfiles(request, response)
-- copy wifibox API-script log
rv,sig,code = redirectedExecute('cp ' .. wifiboxLogFilePath .. ' ' .. LOG_COLLECT_DIR)
-- copy d3dapi script stdout/stderr log
rv,sig,code = redirectedExecute('cp ' .. WIFIBOX_STDOUT_LOG_FILE .. ' ' .. LOG_COLLECT_DIR)
-- capture syslog
rv,sig,code = os.execute('logread > ' .. LOG_COLLECT_DIR .. '/' .. SYSLOG_FILENAME)

View File

@ -10,7 +10,7 @@
LUA=lua
SCRIPT_PATH=/usr/share/lua/wifibox
LOG_FILE=/tmp/wifibox.cgi-fallback.log
LOG_FILE=/tmp/wifibox.stdout.log
cd $SCRIPT_PATH
#echo "CGI invocation" >> $LOG_FILE