One of the most useful scripting commands is "print", which writes text to the screen. It is also important to be able to write text to a log file for later viewing. CHDK provides the "print_screen" function to do this:
http://chdk.wikia.com/wiki/CHDK_scripting#print_screenTo turn on logging to a file, you start your program with "print_screen(nnnn)" where nnnn is a number from 0 to 9999. The resulting file will be named "LOG_nnnn.TXT"
Contrary to what it says in the above documentation, if the log file already exists, it is overwritten, and you lose the previous log data each time your run your script. It would be nice to have the option to append to the same file, or automatically write to a new file if the requested file exists.
Lua has file io functions that can do this, but using them adds a lot of complexity to your scripts, plus they don't work with uBasic. Here's a different solution to the problem. Start your script with :
print_screen(os.date("%H%M"))
print(os.date())
Since the file name contains the 4 digit, 24-hour time, there is no chance you will overwrite the file until at least the next day. That leaves time to move the log files to your computer at the end of the day. The 2nd line of code starts off the log file with the full date and time string.
The uBasic function get_time can do the same thing. I'll leave it to someone else to write the uBasic line. Thanks.