Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Create a simple AppleScript logging function' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create a simple AppleScript logging function
Authored by: foo4thought on Dec 20, '04 11:14:46AM

You'll want to be able to turn on/off the logging. Do it by changing the log_event handler to something like this:

on log_event(themessage, yesDo)
if yesDo then
set theLine to (do shell script ¬
"date +'%Y-%m-%d %H:%M:%S'" as string) ¬
& " " & themessage
do shell script "echo " & theLine & ¬
" [code]>>[/code] ~/Library/Logs/AppleScript-events.log"
end if
end log_event

Use a property or global in the calling script(s) to toggle logging on & off.
e.g.
property doLogTF: false

and change the call to the handler to look like this:

on log_event(themessage, doLogTF)




[ Reply to This | # ]
Create a simple AppleScript logging function
Authored by: leenoble_uk on Dec 20, '04 11:42:29AM

Good idea.

I actually just found the built in way of doing this this morning. I thought about the possibility of using an osaxen rather than a common code script but it's beyond my capabilities. But in the process I opened the system osax file and found the debugstr command which writes a string to the console log. Doh!

I still prefer my script though because it keeps the applescript events in a separate file.

---
So, I said ... well, I can't actually remember exactly what I said. But it was one of the most enormously cruel and frighteningly witty put downs ever.



[ Reply to This | # ]
Toggling the logging function
Authored by: bbumgarner on Dec 20, '04 12:14:18PM

Actually, since you have defined "DoLogTF" as a property, it is therefore, global and you don't need to modify the parameters sent to the handler at all. (That is, to the best of my knowledge -- I could be wrong.) Granted this makes this routine ON or OFF for the entire script.

The advantage of your method is that you can locally turn on and off logging. The disadvantage is if you are working on large scripts it can be just as tedious to find and change each logging statement as it is finding each display dialog statement.

Don't get me wrong, I like the idea of being able to toggle the logging on and off. AND I plan on using it in my own work. I have a Applescript Studio application in the works right now that is over 700 lines long with 20-30 different handlers. This will make debugging easier.



[ Reply to This | # ]
Create a simple AppleScript logging function
Authored by: sdevore on Dec 20, '04 12:37:31PM
I actually have been using a growl ( Growl ) for some reporting when I run appleScripts in debugging mode and some that use growl all the time for notification. I have a similar script that has an optional logLevel parameter that I use so that I can filter the log messages in the console viewer. Sam D

---
--
Foolish consistency is the hobgoblin of little minds -rwe
--

[ Reply to This | # ]