HomeGenie Forum
General Category => Troubleshooting and Support => Topic started by: kevinvinv on June 19, 2016, 10:46:25 PM
-
I have looked at BKENOBI's Log() function a bit but still had a question.
If I want to make my own log... one that is not cluttered up with other log messages... How would I best do this? Can I simply open a file and fprint to it or is there a better way?
Thanks for any advice.
-
You can use the log function and modify it to write whatever you want. I wrote the date/time plus whatever I wanted logged. If you want more/less, you can do that. You could also just use the raw code from the log function to write to a file, but I thought it was much cleaner to create a function.
-
In order to use your log() function, do I have to "enable" the program ? I am not sure how the function name space works.
Also- where would I find the native log() code you mention?
Thanks!
-
I didn't mean to imply the native logging capability. However, there is a way to write to a Linux log file. I've never done it that way but it is a possibility as well. In order to use the log function I posted, you need to have it in your code that you want to enable logging in. I have not been able to use code from one app from another so I always duplicate the log function for each app.
-
I did similar to this and filled the disk so I would also add log rotation. However their is a command to use homegenie logging that is passed through to the nlog framework which would be a better option. I just can't remember it off the top of my head
-
I agree, will be careful. I just need some logging for a short time to figure out why my code is acting up.
-
here you go:
try this:
Program.Log.Trace("Sample trace message");
Program.Log.Debug("Sample debug message");
Program.Log.Info("Sample informational message");
Program.Log.Warn("Sample warning message");
Program.Log.Error("Sample error message");
Program.Log.Fatal("Sample fatal error message");
-
Thanks David,
And then what filename do these get written to? Thanks!!
-
They get written to the main homegenie log file.
/usr/local/bin/homegenie/log/
tail -f logname should help you
-
I'll have to take a look at that approach. I like being able to write log files as I want them, but it would be better to use the native system.
-
I copied your approach but as I said it bit me in the backside and I ran out of space and I didn't notice.. school boy error! I need to put some better monitoring in for my home systems :)
I'm now going to use this approach going forwards :)
What I do need to do though is look at the MIG code and see if I can configure what the 'http' server uses and maybe change the logging level of this / or make it configurable through arguments as the HG log is getting filled with a load of stuff that I don't care about :)
-
I had mine set up so that it would write to a log that was located on a file server rather than on the RPi. However, when I lost the SD card a while back (without having a backup of course), I couldn't figure out how to get the remote directory to map correctly at startup as I did originally. As a result, HG would start prior to the mapping and start writing logs that would be local rather than remote. It was enough of a PITA that I gave up and left it as is. It's not a good idea to do this, but I did it anyway.