xlog框架学习-1

2,284 阅读1分钟

简介

Mars 是微信官方的跨平台跨业务的终端基础组件。

图片

  • comm:可以独立使用的公共库,包括 socket、线程、消息队列、协程等;
  • xlog:高可靠性高性能的运行期日志组件;
  • SDT: 网络诊断组件;
  • STN: 信令分发网络模块,也是 Mars 最主要的部分。

本文学习xlog框架。 环境:macOS 11.2.3,Python 2.7.16,Xcode 12.5 (12E262)

简明教程

源码下载

$ git clone https://github.com/Tencent/mars.git

编译

$ cd mars/mars
$ python build_ios.py

编译完成 image.png

把 mars.framework 作为依赖加入到你的项目中,把mars/libraries/mars_android_sdk/jni 目录的后缀名为 rewriteme 的文件名删掉".rewriteme"和头文件一起加入到你的项目中。

⚠️提示

Showing All Errors Only
/path/to/Example.xcodeproj Building for iOS Simulator, but the linked and embedded framework 'mars.framework' was built for iOS + iOS Simulator.

适配Xcode问题,此处临时移除多余架构,此处仅保留模拟器版本

$ lipo /path/to/mars.framework/mars -thin x86_64 -output /path/to/mars.framework/mars
Failed to load Info.plist from bundle at path /path/to/data/Library/Caches/com.apple.mobile.installd.staging/temp.5drDlB/extracted/Example.app/Frameworks/mars.framework; Extra info about "/Users/USER/Library/Developer/CoreSimulator/Devices/B48C6CC8-0ABD-4EE6-A357-652E882B2F97/data/Library/Caches/com.apple.mobile.installd.staging/temp.5drDlB/extracted/Example.app/Frameworks/mars.framework/Info.plist": Couldn't stat /Users/USER/Library/Developer/CoreSimulator/Devices/B48C6CC8-0ABD-4EE6-A357-652E882B2F97/data/Library/Caches/com.apple.mobile.installd.staging/temp.5drDlB/extracted/Example.app/Frameworks/mars.framework/Info.plist: No such file or directory

我的方案是生成了个info.plist放到mars.framework目录里,下面是info.plist内容

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
  <key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
	<key>CFBundleShortVersionString</key>
  <string>1.0</string>
  <key>CFBundleVersion</key>
  <string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
</plist>
'limits' file not found

需要把调用xlog的文件后缀名改为 .mm

Undefined symbol: _deflate
Undefined symbol: _deflateInit2_
Undefined symbol: _deflateEnd

Build Settings -> Other Linker Flags -> add -lz

解密日志

工具所在目录 mars/mars/log/crypt

$ python decode_mars_crypt_log_file.py /path/to/log

⚠️提示

ImportError: No module named pyelliptic
ImportError: No module named zstandard

未安装 pyelliptic zstandard 需要安装 我本地没有安装pip,需要先安装pip 下载地址get-pip 2.7

$ python /path/to/get-pip.py
$ pip install pyelliptic=1.5.7 # 可能需要把pip所在目录加到环境变量里
$ pip install zstandard

pyelliptic 1.5.8 版本有问题,会报如下错误

Traceback (most recent call last):
  File "/Users/doyan/Documents/workspace-example/mars/mars/log/crypt/decode_mars_crypt_log_file.py", line 9, in <module>
    import pyelliptic
  File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pyelliptic/__init__.py", line 43, in <module>
    from .openssl import OpenSSL
  File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pyelliptic/openssl.py", line 310, in <module>
    OpenSSL = _OpenSSL(libname)
  File "/Users/USER/Library/Python/2.7/lib/python/site-packages/pyelliptic/openssl.py", line 144, in __init__
    self.EVP_CIPHER_CTX_reset = self._lib.EVP_CIPHER_CTX_reset
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 379, in __getattr__
    func = self.__getitem__(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 384, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))