mirror of
https://github.com/Doodle3D/doodle3d-firmware.git
synced 2024-12-22 11:03:48 +01:00
API:info/logtail endpoint
This commit is contained in:
parent
f5bf9c279d
commit
cbbcd2d77b
@ -6,6 +6,7 @@ local printDriver = require('print3d')
|
|||||||
local printerUtils = require('util.printer')
|
local printerUtils = require('util.printer')
|
||||||
local printerAPI = require('rest.api.api_printer')
|
local printerAPI = require('rest.api.api_printer')
|
||||||
local wifi = require('network.wlanconfig')
|
local wifi = require('network.wlanconfig')
|
||||||
|
local printerUtils = require('util.printer')
|
||||||
|
|
||||||
local TMP_DIR = '/tmp'
|
local TMP_DIR = '/tmp'
|
||||||
local LOG_COLLECT_DIRNAME = 'wifibox-logs'
|
local LOG_COLLECT_DIRNAME = 'wifibox-logs'
|
||||||
@ -178,7 +179,41 @@ function M.status(request, response)
|
|||||||
rv = M.access(request, response)
|
rv = M.access(request, response)
|
||||||
if(rv == false) then return end
|
if(rv == false) then return end
|
||||||
end
|
end
|
||||||
response:addData('v', 10)
|
end
|
||||||
|
|
||||||
|
--- Read the tail of a log file
|
||||||
|
-- @string file File to read from the /tmp/ folder
|
||||||
|
-- @number length Max number of lines from the end of the file
|
||||||
|
-- @number offset Offset in lines from the end.
|
||||||
|
function M.logtail(request, response)
|
||||||
|
|
||||||
|
local argFile = request:get("file")
|
||||||
|
local argLength = request:get("length")
|
||||||
|
local argOffset = request:get("offset")
|
||||||
|
|
||||||
|
if argFile == nil or argFile == '' then
|
||||||
|
response:setError("missing file argument")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if argLength == nil or argLength == '' then
|
||||||
|
argLength = 10
|
||||||
|
end
|
||||||
|
if argOffset == nil or argOffset == '' then
|
||||||
|
argOffset = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
response:setSuccess()
|
||||||
|
|
||||||
|
local cmd
|
||||||
|
if argOffset == 0 then
|
||||||
|
cmd = "tail -n "..argLength.." /tmp/"..argFile
|
||||||
|
else
|
||||||
|
cmd = "tail -n "..argOffset.." /tmp/"..argFile.." | head -n "..argLength
|
||||||
|
end
|
||||||
|
|
||||||
|
local output= utils.captureCommandOutput(cmd)
|
||||||
|
output = output:gsub('\n', '\\n')
|
||||||
|
response:addData('tail', output)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user