I wanted to build a simple logMessage function which looks like this:
'Simple logging with timestamp
sub logMessage(message as String)
'Get local time
date = CreateObject("roDateTime")
date.toLocalTime()
print date.asDateString("short-date") date.getHours() ":" date.getMinutes().toStr().trim() ":" date.getSeconds().toStr().trim() "." date.getMilliseconds().toStr().trim() " " message
end sub
I went through all the print statements I had and the application started breaking, because I had to turn all the special print string concatenations into "+", for example:
print "Hello" message
needs to be changed to
logMessage("Hello" + message)
Of course my troubles didn't end there, as anything which is not a string makes string concatenation with "+" fail so I had to add a bunch of
toStr()
calls for integers. But then I found that I had some boolean variables I wanted to output, and there isn't a
toStr()
for that so I had to add if statements.
My plan is to revert all of that and just convert my logMessage sub to a getTimeStamp sub which I will add to the print statements, but I really don't want to do that because I intended to extend the logMessage sub into a full blown logger - have log levels configured centrally and maybe even save to a file.
Is there a better way? Can someone from Roku comment on any plans to make string concatenations using "+" as capable as the print statement?
Thanks and Happy New Year,
Amnon