Logic Machine Forum
Object Logs - How to log changes only? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: General (https://forum.logicmachine.net/forumdisplay.php?fid=2)
+--- Thread: Object Logs - How to log changes only? (/showthread.php?tid=1285)



Object Logs - How to log changes only? - Thomas - 12.03.2018

Hi
I would like to login just changes. Not constant values.
Like: My meteo station sends information about twilight every 10 minutes. It's for security reasons and I don't want to change it. Unfortunately the value is logged every 10 minutes. But there're only two changes during a day.
Can I switch the logging behavior somehow?
What I described in the text above is just an example. The real situation is more complex and my log contains tenths of group objects of this type.

Thank you in advance.


RE: Object Logs - How to log changes only? - Erwin van der Zwart - 12.03.2018

Hi,

Only way to do that is by using a second (virtual) object where log is enabled and only update that secondary object when value changes on the main object.

BR,

Erwin


RE: Object Logs - How to log changes only? - Thomas - 12.03.2018

(12.03.2018, 16:11)Erwin van der Zwart Wrote: Hi,

Only way to do that is by using a second (virtual) object where log is enabled and only update that secondary object when value changes on the main object.

BR,

Erwin

Hmm I don't like this design. Can't I log values from script directly by some internal function or through direct database access?


RE: Object Logs - How to log changes only? - Erwin van der Zwart - 12.03.2018

Hi,

Yes also possible but i don’t see why that design is any better...

BR,

Erwin


RE: Object Logs - How to log changes only? - buuuudzik - 12.03.2018

I think that better could be create some hoovering script which delete unnecessary logsWink


RE: Object Logs - How to log changes only? - Thomas - 13.03.2018

(12.03.2018, 20:06)Erwin van der Zwart Wrote: Hi,

Yes also possible but i don’t see why that design is any better...

BR,

Erwin

Because it doesn't require hundred of additional virtual objects.

1. I create a script for tag "logme" which stores the object value into log
2. I uncheck the "log" checkbox.
3. I set tag "logme" at objects I want to log.

BTW This setup solves problem with readings logging too.

But whole solution depends on information how I can log value into "Object logs" from script?

Thank you


RE: Object Logs - How to log changes only? - admin - 13.03.2018

From event script:
Code:
time, utime = os.microtime()
logtime = time + utime / 1000000

db:insert('objectlog', {
  src = event.srcraw,
  address = event.dstraw,
  logtime = logtime,
  datahex = event.datahex,
  eventtype = event.type:gsub('group', ''),
  sender = event.sender or '',
})



RE: Object Logs - How to log changes only? - Thomas - 13.03.2018

(13.03.2018, 11:28)admin Wrote: From event script:
Code:
time, utime = os.microtime()
logtime = time + utime / 1000000

db:insert('objectlog', {
 src = event.srcraw,
 address = event.dstraw,
 logtime = logtime,
 datahex = event.datahex,
 eventtype = event.type:gsub('group', ''),
 sender = event.sender or '',
})
Perfect! Thank you.


RE: Object Logs - How to log changes only? - Thomas - 13.03.2018

Thank you once again. This solution is perfect. It shrunk my log from 1 newly generated row every second to aprox. ten records per hour.
I've one additional question. I compare changes between new and old values by storing the old value into storage. It works. But isn't there any better option here? Like "event.oldvalue" member in event table? I haven't found it yet.


RE: Object Logs - How to log changes only? - admin - 13.03.2018

Storage is perfectly fine since you need to compare not previously received but previously logged value. You can also query database for last logged value for this object but it will be bit slower.