Skip to content

Commit b92cc44

Browse files
RTLRTL
RTL
authored and
RTL
committed
New example
1 parent 3a05322 commit b92cc44

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

TraceLogger/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# TraceLogger Client
2+
3+
The TraceLogger Client is designed to connect to another Barracuda App Server enabled device and log data from this device without having to use the [HTML based TraceLogger Client](https://realtimelogic.com/ba/doc/?url=auxlua.html#tracelogger).
4+
5+
Use this TraceLogger Client as follows:
6+
7+
1. Open TraceLogger/mako.conf in an editor.
8+
2. Change the TraceLogger peer (trpeer) variable. This variable must be the name or IP address of the device running the Barracuda App Server.
9+
3. Start the Mako Server as follows:
10+
11+
```
12+
cd TraceLogger
13+
mako -l::www
14+
```
15+
16+
For detailed instructions on starting the Mako Server, please refer to our [Mako Server command line video tutorial](https://youtu.be/vwQ52ZC5RRg) and review the [server's command line options](https://realtimelogic.com/ba/doc/?url=Mako.html#loadapp) in our documentation.
17+
18+
4. The peer's log will be printed in the console or saved in mako.log if the server runs as a background process. You may also view the trace using the local server's TraceLogger by navigating to http://localhost or directly to http://localhost/rtl/tracelogger/

TraceLogger/mako.conf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
trpeer="xedge32.local" -- Change this to your device's name/IP
3+
4+
tracelogger=true -- Now you can go to http://localhost/rtl/tracelogger/
5+
6+

TraceLogger/www/.preload

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
local trpeer = require"loadconf".trpeer
2+
assert("string" == type(trpeer), "trpeer must be set in mako.conf")
3+
assert("localhost" ~= trpeer and "127.0.0.1" ~= trpeer, "Can't use 'localhost'")
4+
5+
local sfmt,sbyte=string.format,string.byte
6+
local start -- function set below
7+
8+
-- Must match C code
9+
local TR_set <const> = 1
10+
local TR_data <const> = 2
11+
local TR_acquired <const> = 3
12+
13+
local function log(msg)
14+
tracep(false,0,sfmt("[%s] %s",ba.datetime"NOW",msg))
15+
end
16+
17+
local function notTR()
18+
log"The peer does not appear to be a TraceLogger"
19+
end
20+
21+
local function restart()
22+
ba.timer(function() start(restart) end):set(1000,true)
23+
end
24+
25+
local function traceLoggerReceiver(s)
26+
local data,err = s:read(2000)
27+
if not data or sbyte(data) ~= TR_set then
28+
notTR()
29+
return
30+
end
31+
s:setoption("keepalive",true,15,5)
32+
local tinsert,tconcat=table.insert,table.concat
33+
local collected
34+
while true do
35+
data,err = s:read()
36+
if not data then break end
37+
local cmd=sbyte(data)
38+
if TR_data == cmd then
39+
data=data:sub(2)
40+
if #data > 0 then
41+
local eol = 10 == sbyte(data,#data)
42+
if eol then
43+
if collected then
44+
tinsert(collected,data)
45+
data=tconcat(collected)
46+
collected=nil
47+
end
48+
log(data:sub(1,-2))
49+
elseif eol then
50+
log(data:sub(1,-2))
51+
else
52+
if not collected then collected={} end
53+
tinsert(collected,data)
54+
end
55+
elseif TR_acquired == cmd then
56+
log"Connection closed by another client"
57+
return
58+
end
59+
end
60+
end
61+
if err and "sysshutdown" ~= err then
62+
log("Socket read failed "..tostring(err))
63+
end
64+
restart()
65+
end
66+
67+
start=function(callback)
68+
ba.thread.run(function()
69+
local s,ok,err
70+
local c = require"httpc".create()
71+
local url="http://"..trpeer.."/rtl/tracelogger.service/"
72+
ok,err=c:request{url=url,header={["x-requested-with"]="Lua Client"}}
73+
if ok then
74+
local status=c:status()
75+
if status == 204 then
76+
c:close()
77+
url="ws://"..trpeer.."/rtl/tracelogger.service/"
78+
ok,err=c:request{url=url}
79+
if ok then
80+
s,err=ba.socket.http2sock(c)
81+
if s then
82+
log("Connected to "..url)
83+
s:event(traceLoggerReceiver, "s")
84+
return true
85+
end
86+
end
87+
elseif status == 503 then
88+
log"The TraceLogger is serving another client"
89+
return
90+
elseif status == 401 then
91+
log"Server requires authentication, but it's not implemented"
92+
return
93+
else
94+
notTR()
95+
return
96+
end
97+
end
98+
log(sfmt("Cannot connect to %s: %s",url, err))
99+
if callback then callback() end
100+
end)
101+
end
102+
103+
start()
104+
105+
106+

TraceLogger/www/index.lsp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?lsp
2+
3+
response:sendredirect"/rtl/tracelogger/"
4+
5+
?>

0 commit comments

Comments
 (0)