Write logging to file in Windows

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
Plantje
Posts: 451
Joined: Friday 16 October 2015 7:58
Target OS: Windows
Domoticz version:
Contact:

Write logging to file in Windows

Post by Plantje »

I have found https://www.domoticz.com/wiki/Windows?f ... AO4I_MjTnY with some guidelines as to how to setup logging for Windows. I am running Domoticz as a service so, I added

Code: Select all

-log "C:\Program Files\Domoticz\log"
to the "AppParameters" in the registry. I have opened regedit as administrator and rebooted my system afterwards.
Still "C:\Program Files\Domoticz\log" stays empty.

How can I have Domoticz write the information that I see in the "Log" tab under the settings to a file?

I am trouble shooting a freezing system and I am wondering if just before the freeze anything note worthy happens in Domoticz
plugge

Re: Write logging to file in Windows

Post by plugge »

Plantje wrote: Thursday 11 February 2021 13:20 I have found https://www.domoticz.com/wiki/Windows?f ... AO4I_MjTnY with some guidelines as to how to setup logging for Windows. I am running Domoticz as a service so, I added

Code: Select all

-log "C:\Program Files\Domoticz\log"
to the "AppParameters" in the registry. I have opened regedit as administrator and rebooted my system afterwards.
Still "C:\Program Files\Domoticz\log" stays empty.
I made the same mistake. You must include the filename in the path:

Code: Select all

-log "C:\Program Files\Domoticz\log\domoticz.log"
(for example)
Plantje
Posts: 451
Joined: Friday 16 October 2015 7:58
Target OS: Windows
Domoticz version:
Contact:

Re: Write logging to file in Windows

Post by Plantje »

Thank you very much!
User avatar
waltervl
Posts: 5882
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Write logging to file in Windows

Post by waltervl »

I updated the wiki to prevent more mistakes ;-)

Also this should be fixed in 2020.2 beta 12927 and upwards
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Plantje
Posts: 451
Joined: Friday 16 October 2015 7:58
Target OS: Windows
Domoticz version:
Contact:

Re: Write logging to file in Windows

Post by Plantje »

waltervl wrote: Thursday 11 February 2021 16:37 I updated the wiki to prevent more mistakes ;-)

Also this should be fixed in 2020.2 beta 12927 and upwards
And I am running beta 12901 :)

Is the logging cleaned up automatically every now and then? I noticed the file is already 3MB. I hope it will be pretty useful the next freeze, but still....
Aaaaand, I wasn't able to find how to disable writing the log to a file again. Of course it will be possible by editing the registry again, but should be possible in a different way as well, right?
User avatar
waltervl
Posts: 5882
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Write logging to file in Windows

Post by waltervl »

You could try to update to a newer beta and you will find out. I am just the messenger....
The file will definitely not cleanup by itself. But I have no idea how it can be switched off easy. Perhaps by edit /update the install through control panel, programs?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
plugge

Re: Write logging to file in Windows

Post by plugge »

Plantje wrote: Thursday 11 February 2021 17:26 Aaaaand, I wasn't able to find how to disable writing the log to a file again. Of course it will be possible by editing the registry again, but should be possible in a different way as well, right?
As far as I know you will have to edit the registry and restart the Domoticz service, to make it read the registry again.
To rename the log file, I stop the service, rename the log file and start the service again.
Cumbersome, I know. I would love to see another solution.

The fix in 2020.2 beta 12927 doesn't work on my machine, for some reason.
I get a "parameter error" for NSSM (non sucking service manager) that puts the domoticz service in a "paused" state, similar to the previous build.
Haven't found the cause yet.
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Write logging to file in Windows

Post by erem »

i do not run domoticz on windows, but from general knowledge:

to truncate the log you can write a short cmd script like this

Code: Select all

sc stop <domoticz service name>
del C:\Program Files\Domoticz\log\domoticz.log.old
ren C:\Program Files\Domoticz\log\domoticz.log C:\Program Files\Domoticz\log\domoticz.log.old
sc start <domoticz service name>
and run that as administrator from task scheduler at regular intervals
Regards,

Rob
plugge

Re: Write logging to file in Windows

Post by plugge »

erem wrote: Friday 12 February 2021 11:10 to truncate the log you can write a short cmd script like this
Not quite. "SC" won't stop and wait for a batch file to finish.
"net stop" waits a decent amount of time.
To keep the log file I use the following batch file, for those interested.
(Insert the correct path to the log file.)

Code: Select all

echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set DateTime=%%a
set Yr=%DateTime:~0,4%
set Mon=%DateTime:~4,2%
set Day=%DateTime:~6,2%
set Hr=%DateTime:~8,2%
set Min=%DateTime:~10,2%
set Sec=%DateTime:~12,2%
net stop domoticz
ren "<Path to your logfile>\log\domoticz.log" "domoticz %Yr%-%Mon%-%Day% (%Hr%-%Min%-%Sec%).log"
net start domoticz
EXIT /B %ERRORLEVEL%
And define a task as administrator in Task Scheduler
Plantje
Posts: 451
Joined: Friday 16 October 2015 7:58
Target OS: Windows
Domoticz version:
Contact:

Re: Write logging to file in Windows

Post by Plantje »

Thanks a lot!

Would have been easy if this were part of the core functionality, but we'll have to make do! :)
Littlefield428
Posts: 1
Joined: Friday 26 February 2021 10:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Write logging to file in Windows

Post by Littlefield428 »

type PowerShell in search area and click on "Windows PowerShell"

If you have a .bat (batch) file go to step 3 OR copy your commands to a file and save it with .bat extension (e.g. file.bat)

run the .bat file with following command. PS (location)> <path to bat file>/file.bat | Tee-Object -file log.txt.

expresshr
Last edited by Littlefield428 on Friday 26 March 2021 5:21, edited 1 time in total.
User avatar
waltervl
Posts: 5882
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Write logging to file in Windows

Post by waltervl »

plugge wrote: Friday 12 February 2021 0:06
Plantje wrote: Thursday 11 February 2021 17:26 Aaaaand, I wasn't able to find how to disable writing the log to a file again. Of course it will be possible by editing the registry again, but should be possible in a different way as well, right?
As far as I know you will have to edit the registry and restart the Domoticz service, to make it read the registry again.
To rename the log file, I stop the service, rename the log file and start the service again.
Cumbersome, I know. I would love to see another solution.

The fix in 2020.2 beta 12927 doesn't work on my machine, for some reason.
I get a "parameter error" for NSSM (non sucking service manager) that puts the domoticz service in a "paused" state, similar to the previous build.
Haven't found the cause yet.
The issue on github is reopened for the windows logging.
Can you test if the installation creates or edits the Regkey entries for logging?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
plugge

Re: Write logging to file in Windows

Post by plugge »

waltervl wrote: Thursday 11 March 2021 11:57 The issue on github is reopened for the windows logging.
Can you test if the installation creates or edits the Regkey entries for logging?
Found the culprit: the file path is created in the registry, but without quotes.
So, if the Domoticz log is in a path name with spaces inside, like "Program Files (x86)" nssm.exe wil stumble over the path.
That is most likely the reason why some people (@waaren) experience no problem when installing. Their path doesn't contain spaces
Because of this, I asked @gizmocuz to add the quotes, but apparently the quotes are removed somewhere in the process of writing the registry.

EDIT:
The quotes are there, but InnoSetup seems to remove them. (I'm not familiar with InnoSetup).

EDIT2:
Change your log file to a another path that does not contain spaces, f.e. C:\Users\<user>\Domoticzlog\domoticz.log and everything works fine.
plugge

[Solved] Re: Write logging to file in Windows

Post by plugge »

Fixed in version 2020.2.13077
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest