Mars-日志模块xlog for React-Native (

2019-04-30  本文已影响0人  太阳的小号

本文主要介绍Mars-xlog的使用过程(iOS),与react-native相关部分,则参考了react-native-xlog,暂不做详细介绍

1. 生成mars.framework

python build_ios.py 

2. 在项目中,添加配置资源

3.xlog使用(具体的可以去官方文档查看,这边就简单复制一些主要的代码)


NSString* logPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/log"];
        
// set do not backup for logpath
const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;
setxattr([logPath UTF8String], attrName, &attrValue, sizeof(attrValue), 0, 0);
        
// init xlog
#if DEBUG
xlogger_SetLevel(kLevelDebug);
appender_set_console_log(true);
#else
xlogger_SetLevel(kLevelInfo);
appender_set_console_log(false);
#endif
appender_open(kAppednerAsync, [logPath UTF8String], "Test");
appender_close();

4.我遇到的问题

sudo chmod -R 777 log/
ls -l log

****未完待续****

2019-05-13 接上文

1.日志解压问题

官网明确指出,如果不想使用加密模块或者环境配置不成功,public key 参数设置为空字符即可,解密脚本使用 [decode_mars_nocrypt_log_file.py](https://github.com/Tencent/mars/blob/master/mars/log/crypt/decode_mars_nocrypt_log_file.py), 但这样日志会只压缩不加密。
即调用 appender_open 方法时,最后一个参数 _pub_key 传入空字符:

 appender_open(mode, [logPath UTF8String], [nameprefix UTF8String], "");

官网文档中给的 appender_open 方法多了一个参数,好像是缓存天数的设置,但是我生成的framework包中,其方法是这样的:

void appender_open(TAppenderMode _mode, const char* _dir, const char* _nameprefix, const char* _pub_key);

所以在调用 appender_open 时,最好看一下你生成的framework包中的方法具体是要传那些参数。
解压部分,前提,保证解压脚本,和需要被解压的日志文件,在同一目录下,解压脚本位置:mars/mars/log/crypt/decode_mars_nocrypt_log_file.py (加密解压脚本同路径下,Test_20190426.xlog是你生成的日志文件,可以在控制台的log中找到logPath,然后定位文件)

python decode_mars_nocrypt_log_file.py Test_20190426.xlog
python decode_mars_crypt_log_file.py Test_20190426.xlog

2.对单条日志格式进行修改,和bitcode问题

Mars-日志模块xlog for React-Native (iOS)(2)

上一篇 下一篇

猜你喜欢

热点阅读