Logan: A High‑Performance Mobile Logging Library for Meituan‑Dianping
Logan is Meituan‑Dianping’s native C‑based mobile logging library that uses MMAP caching, streaming compression and encryption, and a unified protocol to eliminate Java‑heap GC pauses, prevent log loss, secure data, and provide efficient retrieval and proactive reporting across dozens of apps.
Background
For mobile applications, a logging library is an essential infrastructure. Meituan‑Dianping’s mobile apps generate tens of billions of log entries daily. To address common issues such as efficiency, security, and log loss, the Logan basic logging library was created.
Existing Problems
Typical mobile logging libraries suffer from:
Performance stutter caused by frequent heap allocations and GC.
Log loss when the app crashes before logs are flushed.
Insufficient security – logs may be exposed in plain text.
Fragmented logs across different types (end‑to‑end, code, crash, analytics) making troubleshooting costly.
At the scale of Meituan‑Dianping, these problems are amplified, leading to unstable and unusable logging modules.
Introduction
Logan (Log + An) is Meituan‑Dianping’s native mobile logging library. It stores various log types locally, supports retrieval and analysis, and is integrated with many internal log systems.
Design
Performance Stutter
Logging involves heavy I/O, which can cause GC pauses and CPU spikes. Logan moves the core logic to a native C library, enabling:
Memory‑only caching to avoid Java heap pressure.
Streaming compression and encryption to reduce CPU peaks.
Cross‑platform support for Android and iOS.
Log Loss
Logan uses an MMAP‑based mechanism. MMAP maps a file into the process address space, allowing memory‑like operations on disk. Benefits include:
Fast, memory‑speed access to the log file.
OS‑controlled write‑back, reducing loss on abrupt termination.
Reduced copy operations, improving I/O efficiency.
If MMAP initialization fails (≈0.002% of cases), Logan falls back to heap‑based caching.
Security
Log files are encrypted using a symmetric key. When uploading, the symmetric key itself is encrypted with an asymmetric key, preventing plain‑text exposure and protecting logs in transit.
Log Fragmentation
Logan defines a custom log protocol that normalizes different log types into a unified format, stores them locally, and aggregates them for centralized display. The platform provides timeline and detail views to help developers locate issues quickly.
Architecture
The overall architecture includes a native C core, a custom log protocol, MMAP for caching, AES encryption, and APIs for proactive reporting.
Log Fragmentation
Logan splits oversized logs into 20 KB fragments, stores each fragment according to the protocol, and reassembles them on the backend.
Log Writing Flow
Performance Evaluation
Benchmarks comparing Java‑based logging with Logan’s C implementation show:
Java: frequent GC pauses.
C: no GC, smoother memory usage.
CPU usage is also lower for the C version because streaming compression/encryption avoids peak loads.
Featured Functions
Log Retrieval
Using Meituan‑Dianping’s PushSDK, Logan can pull local logs from a device after a retrieval command, respecting network type and size limits to save mobile data.
Proactive Reporting
Instead of relying on Push, apps can actively invoke an upload API, bypassing push‑related delays and ensuring logs are sent before user complaints arise.
Online Impact
Since its launch in September 2017, Logan has been stable and significantly improved engineers’ ability to analyze logs and locate issues.
Logan now serves many log types (CAT end‑to‑end, analytics, code, network, push, crash, etc.) across Meituan, Dianping, Meituan Waimai, Maoyan, and other apps.
Future Outlook
H5 SDK
Currently only native Android/iOS versions exist. An H5 SDK is planned to bring the same protocol and aggregation capabilities to pure JavaScript pages.
Log Analysis
Future work includes automated machine analysis of logs to surface key paths, risk detection, and malicious request identification.
Authors
Baifan – Android technology expert, responsible for Logan SDK development and promotion.
Licheng – Senior Android engineer with experience in cross‑platform development and mobile testing.
Recruitment
The Meituan‑Dianping mobile R&D center in Shanghai continuously seeks engineers focused on mobile infrastructure. Contact: hui.zhou#dianping.com.
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.
Meituan Technology Team
Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.
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.
