Skip to content

Replace logcat streaming with persistent Room database logging#13

Merged
greenart7c3 merged 3 commits into
masterfrom
claude/determined-gauss-9ffqfz
Jun 22, 2026
Merged

Replace logcat streaming with persistent Room database logging#13
greenart7c3 merged 3 commits into
masterfrom
claude/determined-gauss-9ffqfz

Conversation

@greenart7c3

Copy link
Copy Markdown
Owner

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

  • New logging infrastructure: Created MorganiteLog object as the centralized logging entry point that persists all log entries to a Room database while maintaining debug-build logcat compatibility
  • Room database implementation: Added LogDatabase, LogDao, and LogEntry entities to store logs with timestamp, level, tag, and message fields
  • Automatic log cleanup: Implemented LogCleanupWorker scheduled as periodic work to delete logs older than 7 days, preventing unbounded database growth
  • Updated all logging calls: Replaced all android.util.Log calls throughout CustomHttpServer.kt and Morganite.kt with MorganiteLog equivalents
  • Simplified log viewing: Changed Morganite.logStream from a manually-managed logcat process to a StateFlow backed by the Room database, providing the last 500 log entries
  • Removed logcat streaming: Eliminated startLogStream() and stopLogStream() methods and their associated job/process management from MainActivity and Morganite

Implementation Details

  • Log entries are inserted asynchronously via coroutine to avoid blocking the main thread
  • The log viewer displays entries in reverse chronological order (oldest first) to auto-scroll to the most recent
  • Debug builds continue to log to logcat for development convenience, while release builds only use the database
  • Stack traces are included in the message field when exceptions are logged
  • The database uses fallbackToDestructiveMigration for development flexibility

https://claude.ai/code/session_01M1FYwYwW7er6DcqGTAVwod

claude and others added 3 commits June 22, 2026 10:33
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
@greenart7c3
greenart7c3 merged commit c9e39a9 into master Jun 22, 2026
1 check passed
@greenart7c3
greenart7c3 deleted the claude/determined-gauss-9ffqfz branch June 22, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants