How thepearl/echo works
Project type and purpose
• This is a Swift logging framework (Swift Package) named “Echo,” accompanied by an iOS example app (EchoExample).
• Purpose: provide a flexible, thread-safe logging core, optional persistent storage (in-memory, file system, Core Data), a built-in SwiftUI/ UIKit log viewer, and log export capabilities for iOS apps.
File structure
• Top level:
– .github/workflows/swift.yml → CI build/test
– Package.swift → SwiftPM package definition
– Sources/Echo → core framework code (Logger, LogViewer, persistence strategies, data model)
– Sources/Resources/EchoDataModel.xcdatamodeld → Core Data model
– EchoExample/… → Xcode project for the demo app
– Tests/EchoTests → unit tests for the framework
• Patterns & modules:
– Core Logging module (Logger + configuration + persistence strategies via Strategy pattern)
– UI module (SwiftUI’s LogViewer, UIKit integration helpers)
– Resources module (Core Data model)
– Example app module demonstrating integration
Extract architecture hints from README
• Core components: Logger, LoggerConfiguration, PersistenceStrategy (.inMemory, .fileSystem, .coreData)
• UI: SwiftUI LogViewer, UIKit view controllers, export API via UIActivityViewController
• Features: log rotation, filtering, search, crash capture, thread-safety
a. Client App (EchoExample)
– SwiftUI Views & UIKit ViewControllers
– EnvironmentObject / injected Echo.Logger
b. Logging Core
– Logger API
– LoggerConfiguration
– LogEntry model
c. Persistence Layer (Strategy)
– InMemoryStore
– FileSystemStore
– CoreDataStore (uses EchoDataModel.xcdatamodeld)
d. Log Viewer (UI)
– SwiftUI LogViewer component
– UIKit wrappers
e. Exporter
– Logger.exportLogs() → String
– UIActivityViewController
f. CI/CD & Packaging
– SwiftPM → builds Sources/Echo into a library
– Xcode workspace (EchoExample + package)
– GitHub Actions (swift.yml)
1. App code → Logger.log(level, category, message)
2. Logger → applies configuration (level filter, rotation)
3. Logger → PersistenceStrategy.store(entry)
4. PersistenceStrategy → writes to memory / file / Core Data
5. LogViewer subscribes to Logger’s data publisher → read entries from store
6. User taps “Export” → Logger.exportLogs() → UIActivityViewController
Architectural patterns & design principles
• Strategy pattern for persistence (swap .inMemory/.fileSystem/.coreData)
• Observer / Publisher–Subscriber (Combine) for real-time UI updates
• MVVM for SwiftUI LogViewer (View ←→ Logger ViewModel)
• Separation of concerns: core logging vs UI vs persistence vs export
• Thread-safe operations (serial queue or locks inside Logger)