ルーム情報 : "droom" (289件)
最近更新されたメモ一覧 :
docs
被リンクメモ一覧 : (1件)
[Tips]
[Home] [List] [Recent] [Orphan] [Help] [Edit] [Remove]

Objective-C : NSLog

NSLogの出力をフックする


extern void _NSSetLogCStringFunction(void(*)(const char*, unsigned, BOOL));

static void _SRLogCString(
    const char* message, unsigned length, BOOL withSysLogBanner)
{
    NSAutoreleasePool*  pool;
    pool = [[NSAutoreleasePool alloc] init];
    
    // Append debug string
    NSString*   string;
    string = [NSString stringWithCString:message length:length];
    [[SRDebugWindowController sharedInstance] appendDebugString:string];
    [[SRDebugWindowController sharedInstance] appendDebugString:@"\n"];
    
    [pool release];
}

- (void)awakeFromNib
{
    // Register customized log function
    setbuf(stderr, NULL);
    _NSSetLogCStringFunction(_SRLogCString);
}

_NSSetLogCStringFunction() で関数を設定してやると、NSLog() がその関数を呼び出すらしい。

from HAPPY Macintosh Developing TIME! : 2004-08-23

[Home] [List] [Recent] [Orphan] [Help] [Edit] [Remove]
-->