1 introduction

1.1 the Mars

Mars is the official cross-platform and cross-business terminal basic component of wechat.

  • Comm: a common library that can be used independently, including sockets, threads, message queues, coroutines, etc.
  • Xlog: a run-time log component with high reliability and performance.
  • SDT: Network diagnostic component;
  • STN: signaling distribution network module, which is the most important part of Mars.

1.2 protobuf

protobuf: Google’s Data Interchange Format. protobuf is an open source serialization framework provided by Google. It is similar to data representation languages such as XML and JSON. Although it is a binary data format, it does not become complicated. Developers define structured message formats according to certain syntax, and then send them to the command line tool. The tool will automatically generate related classes, which can support PHP, Java, c++, python and other language environments. By including these classes in your project, you can easily invoke methods to serialize and deserialize business messages.

2 create a framework

2.1 generation framework

// Download the Mars repository: Git clone https://github.com/Tencent/mars.git / / switch to libraries path CD Mars - master/Mars/libraries / / execute python python scripts Build_apple. py: Input prefix for save directory. Like trunk,br,tag: select build type: 1 represents Mars for iPhone (including Xlog) Enter menu: Build Mars for iPhone.Copy the code

2.2 introduced the framework

// log_crypt.cc.rewriteme, log_crypt.h these two files have been abandoned and can be deleted directly

// Delete. Rewriteme file log_crypt.cc.rewriteme(deprecated),longlink_packer.cc.rewriteme, Shortlink_packer.cc. rewriteme // Drag the project and add libraries SystemConfiguration, CoreTelephony, Foundation, libz. TBD, libresolv9.tbdCopy the code

2.3 xlog

/// Add files (in demo) loghelper.h (.mm), logutil. h(.mm), appender-swift-bridge.h(.mm) /// Add bridge files#import "appender-swift-bridge.h"// Configure xlog with parameters representing :debug level recorded,release level recorded, relative path to save files, file prefix JinkeyMarsBridge().initxlogger (...) / / customlog
JinkeyMarsBridge().log(...)
Copy the code

In didFinishLaunchingWithOptions configuration xlog applicationWillTerminate destory

2.4 introduced protobuf

Against 2.4.1. Pb. Swift

/ / install protobuf brew install protobuf / / install swift - protobuf - plugin git clone https://github.com/apple/swift-protobuf.git CD Swift-protobuf swift build -c release-xswiftc-static-stdlib swift protoc --swift_out=.nameCopy the code

Pb. swift address is install.sh, you can double-click directly to use the following content:

cd $(cd `dirname $0`; pwd) for i in find *.proto do if [ $i == "find" ]; Then continue fi protoc --swift_out=. $I echo "generated file :$i.p.swift" doneCopy the code

Introducing 2.4.2. Pb. Swift

swift-protobuf: Plugin and runtime library for using protobuf with Swift

// pod references pod'SwiftProtobuf'// Add.pb.swift to the project (no.proto) // Use var con = Conversation() con.name ="ashen"
con.notice = "for test"// Transfer data directlylet data = try? con.serializedData()
Copy the code

2.5 (Optional) Adding Bridge Files

Since the framework is written in C++, calling is a big problem for people who don’t know C++ (like me). You can use the relevant files in the demo + swift-oc bridge file to convert directly into classes that swift can call directly

3 Xlog file parsing

3.1 Installing python dependent libraries.

Decode_mars_crypt_log_file. py is only supported by PYTHon2.+,3.+ does not work

Install the dependency library Pyelliptic. If 2.+ and 3.+ versions exist at the same time, use the latest version 1.5.8 of PIP2 PYelliptic

PIP install pyelliptic = = 1.5.7Copy the code

3.2 Decrypting Logger Logs

// Switch to the crypt folder CD Mars/Mars /log/crypt // decrypt Logger python2 decode_mars_crypt_log_file.py logger_20171205.xlog // Logger_20171205.xlog. log indicates decrypted log logsCopy the code

fix bugs:

  • ImportError: No module named pyelliptic

    Cause: Pyelliptic dependency libraries are not installed correctly

    Pip2 install pyelliptic==1.5.7

    Pyelliptic is not installed under 2.+ Python. On MacOS, if both 2.+ and 3.+ Python are installed, pip2 and PIp3 represent installed in 2.+ and 3. You can install pyelliptic by running pip2 install pyelliptic==1.5.7

  • AttributeError: DLSYM (0x7FC443F02F50, EVP_CIPHER_CTX_reset): Symbol not found cause: Pyelliptic 1.5.8 bug fixed: use 1.5.7

    PIP uninstall pyelliptic PIP install pyelliptic==1.5.7Copy the code

resources

  • The sample code
  • Turn batch proto

Reference: Swift access tO wechat Mars_Xlogger hole filling guide — original Jinkey