Out of the box, Freedomotic logging output currently goes to the console. When you start the application, you see a whole load of messages streaming past you on the screen – very messy.
For me, the logging output should go to a file or what I mean really is that it should be sent to syslog. Ultimately, this is the best way to log applications because putting it into a system designed just for logging means you get access to all the things build specifically for dealing with logging. That probably makes no sense, but I will try to explain by way of my setup.
But firstly, lets look at how the logging happens in Freedomotic. Here is an example of some code from my Resol DL2 plugin:
LOG.info("Loading Resol DL2 devices..");
..and its easy to see this creates the output of my informative text to the log. Actually I am telling the plugin something else – I have set the log level of ‘info’ which is important too. When you write to the log, you always specify what level you want. Here are the log levels, and Apple’s suggested usage:
- Emergency (level 0) – The highest priority, usually reserved for catastrophic failures and reboot notices.
- Alert (level 1) – A serious failure in a key system.
- Critical (level 2) – A failure in a key system.
- Error (level 3) – Something has failed.
- Warning (level 4) Something is amiss and might fail if not corrected.
- Notice (level 5) – Things of moderate interest to the user or administrator.
- Info (level 6) – The lowest priority that you would normally log, and purely informational in nature.
- Debug (level 7) – The lowest priority, and normally not logged except for messages from the kernel.
So, in my case the message is ‘purely informational in nature’ – which it is. But why would I want to log this information? Won’t I be filling the log with pointless chatter?
Now, here is the good bit with proper logging inside an application. I can code in whatever log information at whatever level and then at runtime I can decide what logs I want output from the application. This means I can put debugging log entries in the code and have these enabled for debugging, but turned off when I am not interested in seeing them.
Next lets see how how this is done..