Xcode 源码调试微信 xlog
Tencent/masr xlog macOS 源码调试
get include folder
1 |
|
选择1,生成 mars.framework
, 我们主要是使用头文件目录。
gen osx project
1 |
|
执行结果
1 |
|
在 mars/cmake_build/OSX 目录中找到 mars.xcodeproj
1 |
|
将 mars.xcodeproj 作为子工程,添加为依赖项
通过 cmake 生成的 project 定义了生成 mars.framework 的几个相关target, 将 mars.xcodeproj 设置为子工程,
主工程依赖 mars.xcodeproj 定义的target,即可实现 xlog 的源码调试。
- create new macOS project: xlog-test, selcte language: Objective-C
- mars.xcodeproj 添加到 xlog-test 工程中
- 将 mars.framework/Headers 拷贝到 xlog-test 根目录
- xlog-test 配置 header search paths, 值为
$(SRCROOT)/Headers
- xlog-test 配置 linked libraries
- 添加辅助代码,从 MacDemo 中获取, 拷贝到 xlog-test 工程中
- LogHelper 中添加 setup 方法,用于初始化 xlog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23+ (void)setup {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths firstObject];
// init xlog
#if DEBUG
xlogger_SetLevel(kLevelDebug);
mars::xlog::appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
mars::xlog::XLogConfig config;
config.mode_ = mars::xlog::kAppenderAsync;
config.logdir_ = [[libraryDirectory stringByAppendingString:@"/log/"] UTF8String];
config.nameprefix_ = "Test";
config.pub_key_ = "";
config.compress_mode_ = mars::xlog::kZlib;
config.compress_level_ = 0;
config.cachedir_ = "";
config.cache_days_ = 0;
appender_open(config);
} main.m
中初始化调用1
2
3
4
5
6
7
8#import <Cocoa/Cocoa.h>
#import "LogHelper.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
[LogHelper setup];
}
return NSApplicationMain(argc, argv);
}- 用
LogUtil.h
中宏定义打log1
LOG_ERROR(kModuleViewController, @"this is a test log!");
- 愉快地断点,调试吧
Xcode 源码调试微信 xlog
https://yxibng.github.io/2024/03/08/debug-xlog-osx/