Replace logcat streaming with persistent Room database logging#13
Merged
Conversation
Replace the logcat-streaming log viewer with a Room-backed log store so
logs survive process restarts and can be queried reactively.
- Add Room (entity/DAO/database) and a MorganiteLog wrapper that persists
every log line and forwards to android.util.Log only in debug builds.
- Replace all android.util.Log usages across the app with MorganiteLog.
- Drive the in-app log viewer from a DB-backed Flow; remove the
Runtime.exec("logcat ...") streaming code.
- Expire log entries older than 1 week via an hourly WorkManager
PeriodicWork (LogCleanupWorker).
- Add KSP plugin, enable buildConfig, and add Room/WorkManager deps.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M1FYwYwW7er6DcqGTAVwod
Make Morganite.logs a hot StateFlow (via stateIn) so the log screen collects it with collectAsStateWithLifecycle() without an initial value, matching the other StateFlow-backed state on the screen. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M1FYwYwW7er6DcqGTAVwod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the real-time logcat streaming approach with a persistent Room database for storing and retrieving application logs. This provides a more reliable and efficient logging system that survives app restarts and doesn't require continuous logcat polling.
Key Changes
MorganiteLogobject as the centralized logging entry point that persists all log entries to a Room database while maintaining debug-build logcat compatibilityLogDatabase,LogDao, andLogEntryentities to store logs with timestamp, level, tag, and message fieldsLogCleanupWorkerscheduled as periodic work to delete logs older than 7 days, preventing unbounded database growthandroid.util.Logcalls throughoutCustomHttpServer.ktandMorganite.ktwithMorganiteLogequivalentsMorganite.logStreamfrom a manually-managed logcat process to aStateFlowbacked by the Room database, providing the last 500 log entriesstartLogStream()andstopLogStream()methods and their associated job/process management fromMainActivityandMorganiteImplementation Details
fallbackToDestructiveMigrationfor development flexibilityhttps://claude.ai/code/session_01M1FYwYwW7er6DcqGTAVwod