13.02.2020, 08:34
.lp file example. Pass object address/name like this: /user/logs.lp?obj=1/1/1
The number of log entries is limited to 100. You can change this value in query if needed.
The number of log entries is limited to 100. You can change this value in query if needed.
Code:
<?
require('apps')
alias = getvar('obj') or ''
obj = grp.find(alias)
if not obj then
print('object not found')
return
end
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Object logs</title>
<link rel="stylesheet" href="/apps/css/bootstrap.css">
<style>
.table { table-layout: fixed; }
</style>
</head>
<body>
<table class="table">
<tr>
<th>Date/time</th>
<th>Source</th>
<th>Event type</th>
<th>Value</th>
</tr>
<?
query = 'SELECT * FROM objectlog WHERE address=? ORDER BY id DESC LIMIT 100'
items = db:getall(query, obj.id)
for _, item in ipairs(items) do
datetime = os.date('%c', item.logtime)
if item.src > 0 then
src = buslib.decodeia(item.src)
else
src = 'local'
end
if item.eventtype == 'write' then
value = busdatatype.decode(item.datahex, obj.datatype)
else
value = ''
end
?>
<tr>
<td><?=escape(datetime)?></td>
<td><?=escape(src)?></td>
<td><?=escape(item.eventtype)?></td>
<td><?=escape(value)?></td>
</tr>
<? end ?>
</table>
</body>
</html>