Global #define inA SOC

Hi All,
I have been using a global define for NSLog so I can turn debug logging on and off in one place. I put it in the prefix file usually if there is logging across many class files. Is there any way to do this with ASOC script files, and the regular log command, for instance. I know I can create a log handler with an on/off script property for a particular file but it would be nice to have a central “switch.” I’ve been messing around with this but can’t get anywhere. I guess it’s the old global property question.

#define LOGGING_ON 

#define LOG_TEXT( a )         NSLog( a )
#define LOG_TEXT( a )         // (a)

Thanks, Rob

How about setting that property, named debug for instance, in the application delegate and retrieve it later with:

if NSApp's delegate()'s debug() then log "something"

Excactly the same as #define isn’t possible because it’s an compiler instruction which isn’t possible with ASOC

Yes, that would certainly work - I just wanted to avoid a hundred “if .” statements. I guess I could wrap it in a handler.

 logSomething("hello there")

on logSomething(theSomething)
if NSApp's delegate()'s debug() then log theSomething

Cheers, Rob

Well If you want it in a handler you don’t need the if statement. Comment and uncomment the log line, this way you avoid the overhead of if statements.

something like this

if you want to debug in the app delegate

on logSomething_(theSomething)
      log theSomething

when you want debug of

on logSomething_(theSomething)
      --log theSomething

then in any class you can use

NSApp's delegate()'s logSomething_("Hello world")

or from Objective-C

EDIT: Note that in Objective-C you get a compiler warning which is normal. The GCC compiler doesn’t do semantic checks on the ASOC classes.

I didn’t think of that, a nice solution to make the “switch” inside the handler in the delegate - mimics the simple global #define.

Thanks, Rob

I have been doing this kind of thing:

on logSomething_(somedata)
  if aBoolean then
    log somedata

and then I have a global boolean that is “aBoolean” and if true, it logs, if false it won’t. But then no commenting of code needs to happen anywhere, and I can put as many statements in my code. I set up a menu item to set aBoolean to true or false.