Sunday, July 22, 2018

#1 2014-03-14 07:13:58 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

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.

Applescript:

(*
   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


Filed under: logit, syslog, asl, logger

Offline

 

#2 2014-03-14 08:22:32 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5410

Re: A "logit" handler that works under Mavericks

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

Applescript:

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:


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2014-03-14 08:28:32 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: A "logit" handler that works under Mavericks

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.

Last edited by McUsrII (2014-03-14 08:32:27 pm)

Offline

 

#4 2014-03-15 07:25:13 am

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: A "logit" handler that works under Mavericks

Applescript:

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:

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)