A potentially useful log-tracing method

To save myself clicking 'clear' on the logs while testing, I added a button to my DTH. The corresponding action looks like this:

private List insertLogTrace() {
	cal = Calendar.getInstance(location.timeZone)
	def time = "${String.format("%02d", cal.get(Calendar.HOUR_OF_DAY))}" + ":" +
			"${String.format("%02d", cal.get(Calendar.MINUTE))}" + ":" +
			"${String.format("%02d", cal.get(Calendar.SECOND))}"
	log.info("----------------------- ${time} -----------------------")
	null
}

It inserts a timestamp so I can be sure about when actions are registering.

Why do you need to add a timestamp to events in the log that are already timestamped? Notice just to the left of the word "info" on your highlighted line in the logs?

1 Like

I was wondering the same thing...

Ha! You're funny. I did indeed notice that timestamp. I found some sort of 'trace' to be useful. Since there's no possibility of TDD, developing ends up being a matter of copying, pasting, saving, waiting, and switching tabs frequently.

A timestamp can be memorized, and perhaps it's just my feeble brain, but when I'm concentrating on developing something, I don't want to memorize a series of numbers. So a nice clear visual bar is useful to separate events - especially if you want to take several actions, then flip over to the logs to interpret them.

It needn't be a timestamp, of course. It needs to have a uniquing element, though, again to avoid having to memorize or count things, and time is handy because it increases monotonically!

log.debug "---------------------------------------------------------------------"

The point is to have something on the device interface that is not code-bound - so multiple steps in a sequence can be taken, a change can be marked, and then more steps taken. An action can be clicked right on the interface.

A log line in code is fixed in place, and can't be used investigatively without Yet Another round of switch tabs, copy, paste, save, etc.

I'm sure people who don't find it useful won't use it!