This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Logs in visu
#4
.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.
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>
Reply


Messages In This Thread
Logs in visu - by Thomas - 12.02.2020, 16:12
RE: Logs in visu - by Erwin van der Zwart - 12.02.2020, 21:26
RE: Logs in visu - by toujour - 12.02.2020, 23:00
RE: Logs in visu - by admin - 13.02.2020, 08:34
RE: Logs in visu - by Thomas - 13.02.2020, 17:38
RE: Logs in visu - by admin - 14.02.2020, 10:33
RE: Logs in visu - by Erwin van der Zwart - 14.02.2020, 20:16
RE: Logs in visu - by Thomas - 17.02.2020, 14:47
RE: Logs in visu - by sjfp - 02.06.2020, 14:35

Forum Jump: