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.

Event log creation and presentation
#2
You can use storage engine to create a queue, here's a function that adds an item to a list named eventlog and trims the list to contain up to 1000 entries. Date/time is added automatically, so you only need to supply event text. Create event scripts to log whichever info you need.
Code:
function eventlog(text)
  local max = 1000 -- max number of entries

  -- add formatted date
  text = os.date('%a %d/%m/%Y %T ') .. text

  storage.exec('lpush', 'eventlog', text)
  storage.exec('ltrim', 'eventlog', 0, max - 1)
end

To output the list to client side you can create an .lp page and display it in the visualization via iframe. Create a file called eventlog.lp and upload it to user folder via FTP. Set iframe URL to /user/eventlog.lp
Code:
<?
require('apps')
items = storage.exec('lrange', 'eventlog', 0, 999)
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Event log</title>
  <script src="/apps/js/jquery.js.gz"></script>
  <link rel="stylesheet" href="/apps/css/bootstrap.css">
</head>
<body>
<script>
$(function() {
  var items = <? json.write(items) ?>
    , container = $('.container')
    , header;

  $.each(items, function(index, item) {
    var chunks = item.split(' ')
      , newheader = chunks.shift() + ' ' + chunks.shift();

    // output data header each time it changes
    if (newheader != header) {
      header = newheader;
      $('<h3></h3>').text(header).appendTo(container);
    }

    // output log entry
    $('<p></p>').text(chunks.join(' ')).appendTo(container);
  });
});
</script>
<div class="container"></div>
</body>
</html>

Note that newest items come on top of the list.
FTP upload docs: http://forum.logicmachine.net/showthread.php?tid=85
Reply


Messages In This Thread
RE: Even log creation and presentation - by admin - 21.07.2016, 10:15

Forum Jump: