在使用 libComponentLogging 时,有没有办法显示调用 lcl_log() 的线程?
问问题
105 次
2 回答
1
Some of the back-ends already include the thread-id in their log messages, e.g. LogFile and SystemLog do this.
If you want to also include the NSThread's name, you can add that to the back-ends which you are using, e.g. for NSLog, you can add it like this:
--- a/LCLNSLog.h
+++ b/LCLNSLog.h
@@ -84,8 +84,9 @@
// A very simple logger, which redirects to NSLog().
#define _lcl_logger(_component, _level, _format, ...) { \
_lcl_logger_autoreleasepool_begin \
- NSLog(@"%s %s:%@:%d:%s " _format, \
+ NSLog(@"%s [%@] %s:%@:%d:%s " _format, \
_lcl_level_header_1[_level], \
+ [[NSThread currentThread] name], \
_lcl_component_header[_component], \
[@__FILE__ lastPathComponent], \
__LINE__, \
于 2013-10-04T11:04:57.557 回答
0
很简单,这将完成工作(或类似的东西):
[NSThread currentThread].name
于 2013-10-02T08:37:36.077 回答