<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Mega Tech - Medium]]></title>
        <description><![CDATA[Technical insights on scalable systems, mobile security, data engineering, fraud prevention, and modern game technologies. - Medium]]></description>
        <link>https://medium.com/mega-tech?source=rss----60c989e41e22---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Mega Tech - Medium</title>
            <link>https://medium.com/mega-tech?source=rss----60c989e41e22---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:24:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/mega-tech" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building an In-App Logging Viewer for iOS with OSLog]]></title>
            <link>https://medium.com/mega-tech/building-an-in-app-logging-viewer-for-ios-with-oslog-679d9aee30ad?source=rss----60c989e41e22---4</link>
            <guid isPermaLink="false">https://medium.com/p/679d9aee30ad</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[logging-and-monitoring]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Mustafa Eren ]]></dc:creator>
            <pubDate>Thu, 27 Nov 2025 14:06:46 GMT</pubDate>
            <atom:updated>2025-11-27T14:06:45.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68Cq8lQ2-obxpgGkiYbe-A.png" /></figure><h3><strong>Introduction</strong></h3><p>When building a production iOS app with multiple third-party integrations, debugging becomes complex. Traditional ‘<em>NSLog’</em> or ‘<em>print()’</em> statements are hard to filter and organize when you have hundreds of logs from different sources. We needed a solution that would:</p><ul><li>Work efficiently without impacting app performance</li><li>Categorize logs by feature/integration (Firebase, AppsFlyer, Network, Ads)</li><li>Be easily filterable in Console.app during development</li><li>Be accessible directly from within the app for QA testing</li><li>Show full network request/response data</li></ul><p><em>This is where Apple’s `OSLog` framework combined with a custom in-app viewer became our solution.</em></p><h3>Why OSLog?</h3><p><a href="https://developer.apple.com/documentation/OSLog">OSLog</a> is Apple’s unified logging system that offers several advantages over traditional logging methods:</p><h4>1. <strong>Performance</strong></h4><p>OSLog is highly optimized and designed to have minimal impact on app performance. It uses efficient compression and buffering techniques.</p><h4>2. <strong>System Integration &amp; Filtering</strong></h4><p>Logs appear in macOS Console.app where you can filter by subsystem and category. This makes it incredibly easy to filter out noise and focus only on specific types of logs (e.g., only Firebase events, or only network requests).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*nliO5itk_CyWSy4P39BQNw.png" /></figure><h4>3. <strong>Categorization</strong></h4><p>You can organize logs by subsystem and category. In our case, we created categories for:</p><ul><li><strong>Firebase</strong>: All analytics events sent to Firebase</li><li><strong>AppsFlyer:</strong> Attribution and marketing events</li><li><strong>Network:</strong> Full API request/response logs with JSON payloads</li><li><strong>Ad:</strong> Ad loading, display, and click events</li></ul><p><em>This categorization works both in Console.app for developers AND in our in-app viewer for QA.</em></p><p><strong>Security Note:</strong> For network logs containing sensitive data (API responses, user data), we use OSLog’s `privacy: .private` parameter. This redacts the data in Console.app (shows as `&lt;private&gt;`) while still allowing our in-app viewer to access the full content via OSLogStore.</p><h4>4. Log Levels</h4><p>Different log levels (debug, info, notice, error, fault) help prioritize and filter logs based on severity.</p><h4>5. <strong>Runtime Access</strong></h4><p>Unlike `print()` statements, OSLog provides APIs (`OSLogStore`) to read back logs programmatically during the current app session, enabling in-app log viewers.</p><h4>6. <strong>Privacy Controls</strong></h4><p>OSLog has built-in privacy features to redact sensitive information automatically.</p><h3>What is the improvement that we provide?</h3><p>Our iOS app integrates with multiple analytics and advertising platforms:</p><ul><li><strong>Firebase Analytics: </strong>User behavior tracking</li><li><strong>AppsFlyer:</strong> Attribution and marketing analytics</li><li><strong>Ad Networks: </strong>Multiple ad mediation adapters (AppLovin, Google, InMobi, etc.)</li><li><strong>Network Requests:</strong> Backend API calls with request/response data</li></ul><p>When issues occurred in production, we had no visibility into:</p><ul><li>Which analytics events were being fired</li><li>What parameters were sent to third-party SDKs</li><li>Network request/response details</li><li>Ad loading and display events</li></ul><h4>The Testing Pain Point</h4><p>Our QA team faced a particularly frustrating challenge: <strong>verifying analytics events</strong>. Every feature release required them to confirm that the correct events were being fired with the right parameters to Firebase and AppsFlyer.</p><p>Previously, we used `NSLog` to output these events, which had several problems:</p><p>- <em>All logs were mixed together — hard to filter Firebase from AppsFlyer from Network logs</em></p><p><em>- No easy way to see full network request/response JSON in Console.app</em></p><p><em>- Difficult to share specific log evidence with developers</em></p><p><strong>We needed two things:</strong></p><p>1. <strong>Better categorization in Console.app:</strong> Developers should be able to filter logs by category (Firebase only, AppsFlyer only, etc.)</p><p>2. <strong>In-app logging viewer:</strong> QA should be able to see logs directly on the device, especially network request/response data, without connecting to a Mac</p><h3>Implementation</h3><h4>Step 1: Creating Log Categories</h4><pre>enum LogCategory: String, CaseIterable {<br>    case all<br>    case firebase<br>    case appsflyer<br>    case network<br>    case ad<br>}</pre><h4>Step 2: Building the LoggerManager</h4><pre>final class LoggerManager: LoggerManagerProtocol {<br>    private static let bundleId: String = &quot;com.yourapp.bundleid&quot;<br><br>    static func analyticLog(name: String, params: [String: Any], category: LogCategory) {<br>        let categoryName = category.name<br>        let logger = Logger(subsystem: bundleId, category: categoryName)<br>        logger.log(&quot;\(categoryName) Event Name: \(name) - Parameters : \(params)&quot;)<br>    }<br><br>    static func networkLog(url: String, response: String) {<br>        let logger = Logger(subsystem: bundleId, category: LogCategory.network.name)<br>        logger.info(&quot;\(categoryName) Event URL: \(url, privacy: .private) -\n Response: \(response, privacy: .private)&quot;)<br>    }<br>}</pre><h4>Step 3: Reading Logs from OSLogStore</h4><p><em>The key insight is that we can read logs back from the system using `OSLogStore`:</em></p><pre>static func getLogs(category: LogCategory) async throws -&gt; [String] {<br>    let groupedLogs = try await fetchAllLogsGrouped()<br><br>    if category == .all {<br>        return groupedLogs<br>            .filter { $0.key != .network }  // Exclude network logs from &quot;all&quot;<br>            .values<br>            .flatMap { $0 }<br>    } else {<br>        return groupedLogs[category] ?? []<br>    }<br>}<br><br>private static func fetchAllLogsGrouped() async throws -&gt; [LogCategory: [String]] {<br>    return try await Task.detached(priority: .userInitiated) {<br>        let store = try OSLogStore(scope: .currentProcessIdentifier)<br>        let sinceDate = Date(timeIntervalSinceNow: -3600) // Last hour<br>        let position = store.position(date: sinceDate)<br><br>        let predicate = NSPredicate(<br>            format: &quot;subsystem IN %@&quot;,<br>            [bundleId]<br>        )<br><br>        let entries = try store.getEntries(<br>            at: position,<br>            matching: predicate)<br><br>        var groupedLogs: [LogCategory: [String]] = [<br>            .firebase: [],<br>            .appsflyer: [],<br>            .network: [],<br>            .userProperty: [],<br>            .ad: []<br>        ]<br><br>        for entry in entries {<br>            if let log = entry as? OSLogEntryLog {<br>                guard log.subsystem == bundleId else { continue }<br><br>                let logMessage = &quot;&quot;&quot;<br>                    \(entry.date):\(log.category) -&gt; \n<br>                    \(entry.composedMessage)\n<br>                    &quot;&quot;&quot;<br><br>                guard let category = LogCategory.fromName(log.category) else { continue }<br>                groupedLogs[category, default: []].append(logMessage)<br>            }<br>        }<br><br>        // Reverse to show newest first<br>        for key in groupedLogs.keys {<br>            groupedLogs[key]?.reverse()<br>        }<br><br>        return groupedLogs<br>    }.value<br>}</pre><h4><strong>Key Implementation Details</strong></h4><p><strong>1. Background Processing:</strong> We use `Task.detached(priority: .userInitiated)` to read logs on a background thread, preventing UI blocking</p><p><strong>2. Time Window:</strong> We fetch logs from the last hour (`-3600` seconds)</p><p><strong>3. Filtering:</strong> We filter by our app’s bundle ID to only show our logs</p><p><strong>4. Grouping:</strong> Logs are grouped by category in a dictionary</p><p><strong>5. Sorting:</strong> Newest logs appear first</p><h4>Step 4: Building the UI</h4><p>We created a SwiftUI view with:</p><ul><li>Category picker (segmented control)</li><li>Filtered log list</li><li>Expandable/collapsible rows for long content (especially network logs)</li></ul><pre>struct LoggerView: View {<br>    @StateObject private var viewModel = LoggerViewModel()<br><br>    var body: some View {<br>        VStack(spacing: 0) {<br>            categoryPicker<br>                        <br>            if viewModel.isLoading {<br>                loadingView<br>            } else if viewModel.logs.isEmpty {<br>                emptyStateView<br>            } else {<br>                logsList<br>            }<br>        }<br>        .navigationTitle(&quot;Logs&quot;)<br>        .task {<br>            await viewModel.fetchLogs()<br>        }<br>    }<br><br>    private var categoryPicker: some View {<br>        Picker(&quot;Category&quot;, selection: $viewModel.selectedCategory) {<br>            ForEach([LogCategory.all, .firebase, .appsflyer, .network], id: \.self) { category in<br>                Text(category.name).tag(category)<br>            }<br>        }<br>        .pickerStyle(.segmented)<br>        .onChange(of: viewModel.selectedCategory) { _ in<br>            Task {<br>                await viewModel.fetchLogs()<br>            }<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e6_WxW-i7VcKjbr6q0LK1A.png" /></figure><p>The UI includes:</p><ul><li><strong>Category Picker:</strong> Segmented control to switch between log categories</li><li><strong>Loading State</strong>: Shows progress while fetching logs</li><li><strong>Empty State</strong>: Helpful message when no logs are found</li><li><strong>Log List</strong>: Scrollable list of logs with newest first</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDZC49YEdulERjY56iLEVg.png" /></figure><h4>Step 5: Optimizing for Long Content</h4><p>Network logs can be extremely long (full JSON responses with nested objects). We implemented special handling for them:</p><ol><li><strong>Conditional Expansion</strong>: Only network logs have expand/collapse functionality</li><li><strong>Collapsed by Default: </strong>Network log details are hidden until tapped</li><li><strong>Always Visible: </strong>Other categories (Firebase, AppsFlyer, Ad) are always fully visible since they’re typically short (1–2 lines)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfrwsUG8M5rFizuLONkTlQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*dcaqwgiF7kaqhc0Ng0JVDg.png" /></figure><pre>struct LogRowView: View {<br>    let log: String<br>    let index: Int<br>    let category: LogCategory<br>    @State private var isExpanded = false<br><br>    private var isNetworkLog: Bool {<br>        category == .network || (category == .all &amp;&amp; log.contains(&quot;:network:&quot;))<br>    }<br><br>    var body: some View {<br>        VStack(alignment: .leading, spacing: 8) {<br>            HStack {<br>                // Log level badge<br>                Text(&quot;#\(index + 1)&quot;)<br>                    .font(.caption)<br>                    .background(logLevelColor)<br><br>                // Preview text<br>                Text(logPreview)<br>                    .lineLimit(isNetworkLog &amp;&amp; !isExpanded ? 2 : nil)<br><br>                Spacer()<br><br>                // Expand/collapse button only for network logs<br>                if isNetworkLog {<br>                    Button(action: {<br>                        isExpanded.toggle()<br>                    }) {<br>                        Image(systemName: isExpanded ? &quot;chevron.up&quot; : &quot;chevron.down&quot;)<br>                    }<br>                }<br>            }<br><br>            // Full log content - hidden for collapsed network logs<br>            if isNetworkLog == false || isExpanded {<br>                Text(log)<br>                    .font(.system(.caption2, design: .monospaced))<br>                    .textSelection(.enabled)<br>            }<br>        }<br>    }<br>}</pre><h3>Results and Benefits</h3><h4>1. <strong>QA Team Empowerment</strong></h4><p>Our QA team can now verify analytics events, inspect network requests, and debug ad loading issues directly on their test devices — no Mac or Console.app required. They simply open the app, navigate to the logger screen, select a category (e.g., “Network”), and see all relevant logs.</p><h4>2. <strong>Third-Party SDK Verification</strong></h4><p>We can verify that analytics events are being sent with correct parameters to Firebase and AppsFlyer, seeing exactly what data is being transmitted to third-party SDKs.</p><h4>3. <strong>Network Request Inspection</strong></h4><p>Our QA team can now inspect full API request/response JSON directly on the device. Now they can:</p><ul><li>See the exact request URL and parameters</li><li>View the full JSON response</li><li>Verify error responses</li><li>Debug API integration issues independently</li></ul><h4>4. <strong>Performance</strong></h4><p>The logging system has minimal impact on app performance:</p><ul><li>OSLog is highly optimized</li><li>Log reading happens on background threads</li><li>UI only loads visible rows with `LazyVStack`</li></ul><h4>5. <strong>Developer Workflow with Console.app</strong></h4><p>For developers, the categorization in Console.app is a huge improvement. Instead of scrolling through thousands of mixed logs, we can filter by:</p><ul><li>`category:firebase` — Only Firebase events</li><li>`category:network` — Only API calls</li><li>`category:ad` — Only ad-related logs</li></ul><h4>6. <strong>Faster Bug Resolution</strong></h4><p>When issues are reported, we immediately have access to detailed logs. QA can screenshot specific log entries and attach them to bug tickets, dramatically reducing the time to diagnose issues.</p><h3>Conclusion</h3><p><em>This logging system solved a practical problem we had: our QA team needed to verify analytics events and inspect network requests without constantly asking developers for help. OSLog’s categorization made Console.app more usable for us, and adding a simple in-app viewer gave our testers the visibility they needed.</em></p><p><em>The implementation is straightforward — a few hundred lines of code for the manager and UI. If you’re facing similar challenges with third-party SDK integration testing or network debugging, this approach might work for you too.</em></p><p><em>The biggest benefit? Our QA team is now independent. They can verify events, inspect API responses, and debug issues on their own devices. Less back-and-forth, faster testing, fewer “can you check the logs for me?” messages.</em></p><p><em>Not a silver bullet, but a solid improvement to our workflow.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=679d9aee30ad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mega-tech/building-an-in-app-logging-viewer-for-ios-with-oslog-679d9aee30ad">Building an In-App Logging Viewer for iOS with OSLog</a> was originally published in <a href="https://medium.com/mega-tech">Mega Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>