Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective-C NSLog变量:\文件\不带完整路径,输出不带日期时间_Objective C_C Preprocessor_Nslog_Pch - Fatal编程技术网

Objective-C NSLog变量:\文件\不带完整路径,输出不带日期时间

Objective-C NSLog变量:\文件\不带完整路径,输出不带日期时间,objective-c,c-preprocessor,nslog,pch,Objective C,C Preprocessor,Nslog,Pch,出于调试目的,我已将此代码添加到我的.pch。 虽然我对输出非常满意,但我想改进在DLog定义中使用\uuuu FILE\uuuu时打印文件名的方式(没有完整路径) 我使用的是[[NSString stringWithUTF8String:\uuuu文件\uuuuuu]lastPathComponent] 也许你能建议一种更干净/更短的方法吗 #ifdef DEBUG #define DLog(...) NSLog(@"%@ %d %s %s", [[NSString stringWit

出于调试目的,我已将此代码添加到我的
.pch
。 虽然我对输出非常满意,但我想改进在
DLog
定义中使用
\uuuu FILE\uuuu
时打印文件名的方式(没有完整路径)

我使用的是
[[NSString stringWithUTF8String:\uuuu文件\uuuuuu]lastPathComponent]

也许你能建议一种更干净/更短的方法吗

#ifdef DEBUG
    #define DLog(...) NSLog(@"%@ %d %s %s", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __PRETTY_FUNCTION__, __FUNCTION__)
    #define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
#else
    #define DLog(...) do { } while (0)
    #ifndef NS_BLOCK_ASSERTIONS
        #define NS_BLOCK_ASSERTIONS
    #endif
    #define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#endif
更新
如果可能的话,我还想去掉日期时间和应用程序名
(即2012-05-30 16:23:29.795 AppName[11746:12203]
。有什么建议吗?

我想
[[NSString-stringWithUTF8String:\uuuuu文件\uuuuuuuuuu]lastPathComponent]
可能变成
@(\uuuuu文件).lastPathComponent
,考虑到您提出此问题后引入的文字语法。

我认为,
[[NSString stringWithUTF8String:\uuuu FILE\uuuuuuu]lastPathComponent]
可能会变成
@(\uuu FILE\uuuuuu)LASTATESTATABICE ,给出了在你问这个问题之后所引入的文字语法。

我能想到的最接近的是“代码> Prtff<代码>。你试过使用PrimTf函数吗?我有自己的日志代码,它由我的C++静态库和我的ObjuleC++应用程序共享,我采取了一个<代码>静态CON。在每个类中,都有一个宏,它是一个宏,把它传递给日志函数。方法名是用<代码>函数>函数> <代码> >。我认为最接近的是代码> Prtff<代码>。你试过使用Primf函数吗?我有自己的日志代码,它由我的C++静态库和我的ObjuleC共享。++应用程序和我在每个类中都保存了一个
static const char*m_classname
,以及一个将其传递给log函数的宏。