How ZanLogger Revolutionizes Mobile App Debugging with High‑Performance Log Management
The article explains the design and implementation of Youzan’s ZanLogger, a mobile logging platform that streamlines issue diagnosis by providing secure, efficient log collection, retrieval, and analysis features—including active and passive reporting, mmap‑based I/O reduction, dynamic symmetric key encryption, and multi‑dimensional storage—while detailing performance benchmarks and future enhancements.
Background
Mobile log systems are critical for diagnosing runtime issues. Previously, merchants reported problems to customer service, which created tickets for developers, causing repeated communication, information loss, and high time cost.
Challenge
A comprehensive logging platform was required to provide easy mobile integration, secure log writing, stable retrieval, periodic cache clearing, and multi‑level filtering (account, shop, business). After multiple iterations, the Youzan Log Platform was launched in 2019.
Architecture
The platform builds on Youzan’s common services such as monitoring, alerting, and messaging. Backend services handle metadata aggregation, log retrieval management, and merchant‑uploaded log storage. The frontend provides device query, log retrieval entry, and filter UI. The mobile SDK (ZanLogger) depends on Youzan’s long‑link library, device‑info library, config center, network library, and security library.
Log Information
Each log entry contains basic information (shop ID, app version, OS version, network status) and business‑specific events. Basic info is written once and updated only when changed to reduce redundancy; business events are injected by developers as custom logs.
Log Reporting
Active reporting: Users can manually trigger log upload from the app’s settings page.
Log retrieval: Developers query a device by phone number or shop ID and pull the corresponding log file from the platform.
Log Levels
ZanLogger defines four levels: log.d (debug), log.i (info), log.w (warning), and log.e (error). Error logs are forwarded to Youzan’s alert system and notified via SMS, phone, WeChat, or email.
SDK Performance
Performance Bottleneck
Traditional logging writes each entry directly to a file, causing a user‑space → kernel‑space → file I/O path with two memory copies. Frequent writes lead to heavy I/O, frequent GC, and UI jank even on background threads.
mmap Optimization
ZanLogger offloads writes to native C++ using mmap. Logs are written directly to memory, bypassing kernel buffers and reducing copies to a single operation, dramatically lowering I/O overhead and eliminating UI stalls.
Benchmark Results
Java writes took more than three times longer than mmap writes for both 1,000‑record and 10,000‑record tests. Java exhibited frequent GC and severe memory jitter, while mmap showed smooth, stable performance.
Log Integrity
Loss Scenarios
User force‑quits the app.
App crashes, runs out of memory, or is reclaimed by the system.
Internal logger defects prevent complete writes.
Binary File Format
Each log file consists of a header (date, version, encryption method) and a content area (encrypted logs). During decryption, the header is parsed to obtain the key and algorithm, then the content is decrypted to retrieve raw logs.
Security
Dynamic Symmetric Key Generation
A daily symmetric key is derived from device identifiers, timestamps, and obfuscation parameters. A bridge hook supplies the raw key, which is then processed to match the chosen algorithm.
// Initialize key generation handle
char *secretKeyGenerator(int version){}
static void initSecretKeyGenerator(char *(*secretKeyGenerator)(int));Key Storage with Asymmetric Encryption
The generated symmetric key is encrypted with a backend‑provided public key and stored in the file header alongside the public‑key ID. The backend retrieves the public‑key ID, decrypts the key with the corresponding private key, and uses it to decrypt the log content.
Featured Functions
ZanLogger supports uploading custom sandbox files and configuration files together with logs. Developers can specify additional files via a JSON string; the platform automatically matches common paths (e.g., .sqlite-wal, .sqlite-shm) and compresses them for upload.
Online Adoption
ZanLogger is integrated into Youzan’s Mini‑Mall, Retail, Selection, Beauty, and Meeting apps. Customer service can retrieve logs by user ID, dramatically reducing communication overhead and speeding up issue resolution.
Future Outlook
Log Analysis
Initial analysis pipelines will process retrieved logs to surface actionable insights for developers.
Multi‑Dimensional Storage
Beyond chronological storage, logs will be categorized by type (error, warning, debug) into separate files to simplify large‑scale analysis.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Youzan Coder
Official Youzan tech channel, delivering technical insights and occasional daily updates from the Youzan tech team.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
