Mobile Logging Library: Design a Thread-Safe In-App Logger for Android and iOS
Interview Experience
Problem
Design a lightweight in-app logging library for a mobile client. The library must support multiple log levels, write logs to local disk without blocking the UI thread, and expose an API to upload buffered logs to a remote endpoint on demand.
kotlin
// Android (Kotlin)
class MobileLogger(val maxBufferSize: Int, val logDir: File) {
fun log(level: Level, tag: String, message: String)
fun flush(): List<LogEntry>
fun upload(endpoint: String, onComplete: (Boolean) -> Unit)
}
enum class Level { VERBOSE, DEBUG, INFO, WARN, ERROR }
Scenario: A user reports a crash. Your library should let the support team retrieve the last 500 log lines from their session without requiring a new build.
Follow-ups
- How do you ensure logs are not lost if the app is force-killed mid-write?
- What strategy prevents the log directory from growing unbounded on a low-storage device?
- How would you redact PII (emails, tokens) before writing to disk?
- Describe how you would unit-test the disk-write path without hitting real I/O.
Full Details
Problem
Design a lightweight in-app logging library for a mobile client. The library must support multiple log levels, write logs to local disk without blocking the UI thread, and expose an API to upload buffered logs to a remote endpoint on demand.
kotlin
// Android (Kotlin)
class MobileLogger(val maxBufferSize: Int, val logDir: File) {
fun log(level: Level, tag: String, message: String)
fun flush(): List<LogEntry>
fun upload(endpoint: String, onComplete: (Boolean) -> Unit)
}
enum class Level { VERBOSE, DEBUG, INFO, WARN, ERROR }
Scenario: A user reports a crash. Your library should let the support team retrieve the last 500 log lines from their session without requiring a new build.
Follow-ups
- How do you ensure logs are not lost if the app is force-killed mid-write?
- What strategy prevents the log directory from growing unbounded on a low-storage device?
- How would you redact PII (emails, tokens) before writing to disk?
- Describe how you would unit-test the disk-write path without hitting real I/O.
About This Question
This is a candidate experience report from a notion interview during the onsite round.
It covers the following topics: Strings, Ios, Android, Coding, Onsite .