Quiet log for JSCocoa

38 views
Skip to first unread message

mugginsoft

unread,
Nov 20, 2012, 6:19:45 AM11/20/12
to jsc...@googlegroups.com
The default JSCocoa log function calls NSLog() and is verbose.
Rather than modifying the JSCocoa bundle a quieter log function can be implemented in the client app.
The example below overrides the default log behaviour.

Required JS:

// override default JSCocoa implementation

function log(str)

{

    __jsc__.qlog_('' + str)

}


// explicit quiet log

function qlog(str)

{

    __jsc__.qlog_('' + str)

}


// verbose log uses the default JSCocoa implementation

function vlog(str)

{

    __jsc__.log_('' + str)

}


A JSCocoaController category:

#import <Foundation/Foundation.h>


/*

 

QuietLog

 

 */

void QuietLog (NSString *format, ...) {

    va_list argList;

    

    va_start (argList, format);

    NSString *message = [[NSString alloc] initWithFormat: format arguments: argList]; // autorelease if not ARC

    va_end (argList);

    

    fprintf (stderr, "%s\n", [message UTF8String]);

    

}


@implementation JSCocoaController (Mugginsoft)


/*

 

 + qlog

 

 */

+ (void)qlog:(NSString *)value

{

    QuietLog(@"%@", value);

}


/*

 

 - qlog

 

 */

- (void)qlog:(NSString *)value

{

    QuietLog(@"%@", value);

}

@end

Reply all
Reply to author
Forward
0 new messages