How to log when a event is triggered

Moderator: leecollings

Post Reply
JuanUil
Posts: 497
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

How to log when a event is triggered

Post 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
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: How to log when a event is triggered

Post 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"
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to log when a event is triggered

Post by jvdz »

Any print() statement output from the lua event scripts is logged in /var/log/domoticz.log (assuming you have that active)

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
JuanUil
Posts: 497
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: How to log when a event is triggered

Post 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!!
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
JuanUil
Posts: 497
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: How to log when a event is triggered

Post 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?
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: How to log when a event is triggered

Post by Egregius »

Logfile options are set in /etc/init.d/domoticz.sh (domoticz startup script).
JuanUil
Posts: 497
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: How to log when a event is triggered

Post by JuanUil »

And what do I need to change there?
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
albaga
Posts: 10
Joined: Sunday 13 December 2015 19:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to log when a event is triggered

Post 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.
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to log when a event is triggered

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
JuanUil
Posts: 497
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: How to log when a event is triggered

Post by JuanUil »

Thnx guys,
going to work on it
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest