Page 1 of 1

Write logging to file in Windows

Posted: Thursday 11 February 2021 13:20
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

Re: Write logging to file in Windows

Posted: Thursday 11 February 2021 13:39
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)

Re: Write logging to file in Windows

Posted: Thursday 11 February 2021 13:52
by Plantje
Thank you very much!

Re: Write logging to file in Windows

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

Also this should be fixed in 2020.2 beta 12927 and upwards

Re: Write logging to file in Windows

Posted: Thursday 11 February 2021 17:26
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?

Re: Write logging to file in Windows

Posted: Thursday 11 February 2021 17:48
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?

Re: Write logging to file in Windows

Posted: Friday 12 February 2021 0:06
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.

Re: Write logging to file in Windows

Posted: Friday 12 February 2021 11:10
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

Re: Write logging to file in Windows

Posted: Sunday 14 February 2021 12:56
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

Re: Write logging to file in Windows

Posted: Sunday 14 February 2021 13:47
by Plantje
Thanks a lot!

Would have been easy if this were part of the core functionality, but we'll have to make do! :)

Re: Write logging to file in Windows

Posted: Friday 26 February 2021 10:32
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

Re: Write logging to file in Windows

Posted: Thursday 11 March 2021 11:57
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?

Re: Write logging to file in Windows

Posted: Thursday 11 March 2021 12:23
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.

[Solved] Re: Write logging to file in Windows

Posted: Saturday 13 March 2021 9:08
by plugge
Fixed in version 2020.2.13077