more G-Labs products

Author Topic: Mono logging (Linux and Windows)  (Read 825 times)

February 01, 2016, 11:17:57 PM
Read 825 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
HG offers the activity log in the interface which can help track basic actions such as module on/off.  It cannot diagnose more problematic issues such as errors or crashes.  In order to see the full debug information, the user needs to view the mono output.  This can be done in a few ways depending on the system.

HG interface (Linux or Windows):
1) Today/Yesterday log file:  The HG web interface has access to download the current and previous day mono output files.  These files contain all actions that the mono output obtained through other methods can provide.  The down side is that there is a delay before HG writes to the file (output is not real time).  Thus you may have to wait some time before the current activity is written to the log.  If there is a crash, it may not be displayed as the log might not write prior to the service stopping.

Linux:
1) Use NLog: HG already outputs events to the Linux log system so you could use the data that's already written there.  You will have to figure out NLog, but this would probably be the best method as it avoids creating more data than is needed.

2) Stop the HG service and run from command line:
Code: [Select]
sudo service homegenie stop
cd sudo /usr/local/bin/homegenie
sudo mono HomeGenie.exe
This should work, but Gene has recommended against this method in the past.  I don't think this solution is as good as the next one.

3) Write mono output to a file:  Modify /usr/local/bin/homegenie/startup.sh to write the mono to a file rather than dumping it to /dev/null.  Change the line
Code: [Select]
sudo $MONO HomeGenie.exe >/dev/null  2>&1to
Code: [Select]
sudo $MONO HomeGenie.exe >/usr/local/bin/homegenie/log/mono.log  2>/dev/nullThis approach will dump all output that you would see on the screen from approach 2 to a file in the homegenie/log directory.  The output is real time and can be viewed remotely.  If you use Windows for the remote system, you will need to either ssh in or use samba to share things for remote viewing.

WARNING: If you are running on a RPi and using an SD card as the log file destination, you should be aware that theoretically there is a limit to the number of times a specific memory location can be written to.  If you use option 3, you are technically shortening the life of your SD card.  I keep regular backups using rpi-clone in case this theoretical SD failure actually becomes a reality and I have to start over.  Alternately, you can write to a different flash drive or network drive.

Windows:
1) Stop the HG service and run from command line:  Select the HG service icon in the start menu and select "stop service".  Open a command prompt, navigate to the HG directory, and launch manually:
Code: [Select]
cd "C:\Program Files\HomeGenie
Homegenie.exe
This does work and is good for quickly solving issues that come up and can be repeated at will.  If the issue is intermittent and debugging will take some time or the output will be longer, you can redirect the output to a file
Code: [Select]
cd "C:\Program Files\HomeGenie
Homegenie.exe>log\mono.log

2) Write mono output to a file:  If you want to always write the mono output to a file for some reason, option 1 might not work well during reboots as you will either lose debugging at reboot or HG may not start without manual interaction.  In this case, you can have HG start from a batch file that is launched at system start.  Create a file in the HG directory named "homegenie.bat" with the following script:
Code: [Select]
start "HomeGenie" /d"C:\Program Files\HomeGenie" /min cmd /c "HomeGenie.exe>D:\Array1\Misc\HomeAutomation\HomeGenie\log2\mono.log"Stop the HG service:
Code: [Select]
Open Services from the control panel
Select "HomeGenie Automation Server"
Change Startup type to manual
Click stop
Close services console
Set the batch file to launch at startup.  This can be done by creating a shortcut in the start menu under "programs\startup" however, HG won't start until you log on.  I recommend adding the batch file to the system run menu in the registry instead.
Code: [Select]
start menu->run "regedit"
navigate to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Create a new string value with value name=HomeGenie and value data="C:\Program Files\HomeGenie\HomeGenie.bat" (including quotes
When you restart, you will now see a minimized command prompt window and the data will go to the mono.log file.  If you prefer, you could actually create a service for this batch file, but I won't include that here as I don't think this is likely all that useful.  Also, the registry step is probably further than most would need anyway.


There are no comments for this topic. Do you want to be the first?