What are the numbers in the square brackets in NSLog() output?

扶醉桌前 提交于 2019-12-17 10:53:33

问题


What is the stuff between the [] in the log message below? I get this in my iPhone app, and I have no idea where the message is coming from. My first guess would be a line number, but which file would it be in?

2010-10-19 08:56:12.006 Encore[376:6907]

回答1:


The first number is the process ID, the second is the logging thread's Mach port. A desktop example:

2010-10-19 17:37:13.189 nc_init[28617:a0f] nc <CFNotificationCenter 0x10010d170 [0x7fff70d96f20]> - default <CFNotificationCenter 0x10010d2a0 [0x7fff70d96f20]>

(gdb) i thread
Thread 1 has current state "WAITING"
    Mach port #0xa0f (gdb port #0x4203)
    frame 0: main () at nc_init.m:10
    pthread ID: 0x7fff70ebfc20
    system-wide unique thread id: 0x167b49
    dispatch queue name: "com.apple.main-thread"
    dispatch queue flags: 0x0
    total user time: 13232000
    total system time: 16099000
    scaled cpu usage percentage: 0
    scheduling policy in effect: 0x1
    run state: 0x3 (WAITING)
    flags: 0x0
    number of seconds that thread has slept: 0
    current priority: 31
    max priority: 63
    suspend count: 0.

(gdb) p/x (int)mach_thread_self()
$1 = 0xa0f

Notice how 0xa0f is reported as the thread's Mach port.




回答2:


first number is the process ID, unsure about second, this line will precede every line thats printed to console from your application.

Possibly a NSLog(@""); is causing this.

Is your application running or has it crashed by this stage?




回答3:


The first number is the process ID, as the others have said. The second number is the thread ID, at least I'm pretty sure that's what it is...




回答4:


It's a process ID in fact. You can see that in the GDB console with a line somewhere that should read "[Switching to process 376]".



来源:https://stackoverflow.com/questions/3968679/what-are-the-numbers-in-the-square-brackets-in-nslog-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!