NSLog中的前缀是什么意思? [英] What does the prefix in NSLog mean?

查看:137
本文介绍了NSLog中的前缀是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用NSLog时,得到的输出类似于以下内容:

When I use NSLog, I get output similar to the following:

2012-01-24 17:05:32:860 App [21856:71939] {记录在此处}

2012-01-24 17:05:32:860 App[21856:71939] {logging goes here}

我认识到'2012-01-24 17:05:32:860'是日期,'App'是应用程序名称,但是我不知道'[21856:71939]'是什么意思.有人可以告诉我这是什么以及在哪里生成的吗?

I recognize that '2012-01-24 17:05:32:860' is the date, 'App' is the app name, but I have no clue what '[21856:71939]' means. Can someone fill me in on what that is and where it's generated at?

我要做的就是记录好排列的日志,这样很容易阅读,但是'[21856:71939]'的数字变化足以混淆所有对齐尝试.如果我知道如何生成[[21856:71939]"中的数字,则可以根据需要添加空格以使其正确排列,但这是我目前唯一的想法.

All I'm trying to do is get logging that lines up nicely so it's easy to read, but the '[21856:71939]' varies in digits enough to mess up any alignment attempts. If I knew how the numbers in '[21856:71939]' were generated, I could add spaces as needed to make it line up correctly, but that's my only idea at this point.

任何帮助将不胜感激:)

Any help would be much appreciated :)

推荐答案

21856是进程ID. 71939是线程ID.

21856 is the process id. 71939 is the thread id.

您可以使用以下方法自行生成日志的这一部分:

You can generate this portion of the log on your own using:

[NSString stringWithFormat:@"[%ld,%lx]",
    (long) getpid(),
    (long) pthread_mach_thread_np(pthread_self())];


编辑2014-09-23:

至少在iOS 8的模拟器上,第二个数字现在是线程的pthread_threadid_np.

At least on the simulator in iOS 8, the second number is now the pthread_threadid_np of the thread.

    __uint64_t threadId;
    if (pthread_threadid_np(0, &threadId)) {
        threadId = pthread_mach_thread_np(pthread_self());
    }

    [NSString stringWithFormat:@"[%ld,%llu]", (long) getpid(), threadId]

这篇关于NSLog中的前缀是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆