A "logit" handler that works under Mavericks

Hello.

It appears to me that there has been some changes to asl, syslog, and logger in Mavericks, so I have found no way to make the logging to a log file that shows up in Console.app to work.

Here is an AppleScript Library that replaces the old functionality.

(*
	We write a log message to a file.
	usage:
	use AppleScript version "2.3"
	use debug : script "ase_debug"
	
	debug's logit("webPageHelper","We started")
*)

use AppleScript version "2.3"
use scripting additions

to logit(appname, amessage)
	tell (current date)
		set amessage to short date string of it & " " & time string of it & " '" & appname & "'  " & amessage & linefeed
	end tell
	set logsFolder to ((path to library folder from user domain as text) & "Logs:")
	set logfilename to logsFolder & appname & ".log"
	set fref to open for access logfilename with write permission
	try
		write amessage to fref starting at eof
		close access fref
	on error
		close access fref
	end try
end logit

If you’re not too worried about the app name, you could use this ASObjC version:

use framework "Foundation"

on logIt:theVal
	if class of theVal is in {real, integer, date} then set theVal to theVal as text
	current application's NSLog("%@", theVal)
end logIt:

Hello.

Thank you for writing that one Shane, I believe both have their uses, though I’ll rework yours to take a string as argument, so the signature will look a bit like mine, but just prints it to the Console.log, like all cocoa apps. Then I can filter on the app/script name, and avoid the clutter in the log file list. But yours if course good as well, there isn’t much need for a logfile if you are looking at the console during running an app during development anyway.

However, sometimes I prefer logging to a specific file, if say an app misbehaves once per week or so, because then I don’t have to deal with rotated logs and so on.

use framework "Foundation"
# The conventions is that if you need a 'tag' of some kind into the message text, you'll provide it for yourself!
# this is intended to send "one off" messages to the console during app development.
on logToConsole:messageText
	current application's NSLog("%@", messageText)
end logToConsole: