PRPDebug

来源:互联网 发布:linux文件压缩zip命令 编辑:程序博客网 时间:2024/06/06 02:52

#ifdef PRPDEBUG

#define PRPLog(format...) PRPDebug(__FILE__, __LINE__, format)

#else

#define PRPLog(format...)

#endif


#import <Foundation/Foundation.h>


void PRPDebug(constchar *fileName, int lineNumber,NSString *format, ...);


void PRPDebug(constchar *fileName, int lineNumber,NSString *fmt, ...) {

   va_list args;

   va_start(args, fmt);

    

   static NSDateFormatter *debugFormatter =nil;

   if (debugFormatter == nil) {

        debugFormatter = [[NSDateFormatteralloc] init];

        [debugFormattersetDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    }

    

   NSString *msg = [[NSStringalloc] initWithFormat:fmtarguments:args];

   NSString *filePath = [[NSStringalloc] initWithUTF8String:fileName];    

   NSString *timestamp = [debugFormatter stringFromDate:[NSDate date]];

    

    NSDictionary *info = [[NSBundlemainBundle] infoDictionary];

    NSString *appName = [infoobjectForKey:(NSString *)kCFBundleNameKey];

    fprintf(stdout,"%s %s[%s:%d] %s\n",

            [timestampUTF8String],

            [appNameUTF8String],

            [[filePathlastPathComponent] UTF8String],

            lineNumber,

            [msgUTF8String]);

    

   va_end(args);

    [msgrelease];

    [filePathrelease];

}



0 0
原创粉丝点击