Updated 2026-10-13: The 2014 implementation wrote directly under the external-storage root, which is outdated. Android 10 (API 29) introduced scoped storage; Android 11 (API 30) ignores
requestLegacyExternalStoragefor apps targeting API 30 or higher. The replacement below uses app-internal storage, requires Android 4.4 (API 19) or later, and needs no storage permission. See Android 11 storage changes.
Log2File records logs explicitly supplied by an Android application to a file. It is useful when:
- A computer cannot be connected for debugging, for example because USB OTG occupies the port.
- Logs are difficult to capture in real time.
- An intermittent bug requires a record of the operations preceding it.
- I’ll leave the other uses to your imagination.
It saves only the content passed to w(); it does not automatically capture system logcat. Use the Logcat tools for system logging.
0. Introduction
This article originally appeared on my CSDN blog before moving here. The original GitHub source URL returned 404 during this update, so the replacement implementation is included below.