30.12.2021, 14:34
(21.07.2016, 10:15)admin Wrote: 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
Hi. I would like to use this code, but i don't know where i should put this code:
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