Page 1 of 1
How to log when a event is triggered
Posted: Wednesday 23 December 2015 17:16
by JuanUil
Hi all,
I would like to log when an event is triggered over a longer period of time.
Can I write the log to a file on my raspberry?
And if yes, does anybody have an example in LUA script how to do this?
Many thnx in advance for your help
Jan
Re: How to log when a event is triggered
Posted: Wednesday 23 December 2015 17:33
by Egregius
Don't know about lua, in PHP it's quite easy. I made a function for it:
Code: Select all
$LogFile = '/var/log/floorplan.log';
function logwrite($msg,$msg2 = NULL) {
global $LogFile;
$time = microtime(true);
$dFormat = "Y-m-d H:i:s";
$mSecs = $time - floor($time);
$mSecs = substr(number_format($mSecs,3),1);
$fp = fopen($LogFile,"a+");
fwrite($fp, sprintf("%s%s %s %s\r\n", date($dFormat), $mSecs, $msg, $msg2));
fclose($fp);
}
Example:
//Example:
logwrite('Switch '.$idx.' '.$name.' '.$cmd.' by '.$user.' = '.$reply);
writes something like "2015-12-23 17:33:01.657 Switch 26 TV On by Tobi = OK"
Re: How to log when a event is triggered
Posted: Wednesday 23 December 2015 17:38
by jvdz
Any print() statement output from the lua event scripts is logged in /var/log/domoticz.log (assuming you have that active)
Jos
Re: How to log when a event is triggered
Posted: Wednesday 23 December 2015 17:39
by JuanUil
Tnx for your quick reply.
I really don't know anything about PHP but this is exactly what I need.
If anybody knows how to translate this in LUA I would be verry, verry grateful!!
Re: How to log when a event is triggered
Posted: Wednesday 23 December 2015 17:42
by JuanUil
Any print() statement output from the lua event scripts is logged in /var/log/domoticz.log (assuming you have that active)
Jos
How can I make that active Jos?
Re: How to log when a event is triggered
Posted: Wednesday 23 December 2015 17:44
by Egregius
Logfile options are set in /etc/init.d/domoticz.sh (domoticz startup script).
Re: How to log when a event is triggered
Posted: Wednesday 23 December 2015 17:49
by JuanUil
And what do I need to change there?
Re: How to log when a event is triggered
Posted: Wednesday 23 December 2015 19:41
by albaga
On domoticz.sh file, will have a line that says:
DAEMON_ARGS="-daemon -www 8080 -sslwww 443"
Replace it by this:
DAEMON_ARGS="-daemon -www 8080 -sslwww 443 -log /tmp/domoticz.txt"
I think it will work well.
Re: How to log when a event is triggered
Posted: Wednesday 23 December 2015 23:08
by jvdz
This is what I have from the standard distribution image:
Code: Select all
DAEMON_ARGS="-daemon -www 8080 -sslwww 443 -log /var/log/domoticz.log"
Jos
Re: How to log when a event is triggered
Posted: Thursday 24 December 2015 9:30
by JuanUil
Thnx guys,
going to work on it