Skip to content

Echo: A flexible and lightweight logger with in-app visualiser for Swift iOS applications.

License

Notifications You must be signed in to change notification settings

Commencement-Technology/Echo

Β 
Β 

Repository files navigation

Echo

⚠️ IMPORTANT: 🚧 This package is still in development. 🚧 Please take that into consideration. πŸ›‘ It should NOT be used in production! πŸ›‘

Echo is a flexible and easy-to-use logging framework for Swift applications. It is made with internal testers in mind. It provides a robust solution for capturing, storing, and analyzing log data in iOS applications in order to simplify exchanges between devs and internal testers.

Table of Contents

  1. Features
  2. Requirements
  3. Installation
  4. Usage
  5. Configuration Options
  6. SwiftUI Integration
  7. UIKit Integration
  8. Built-in Log Viewer
  9. Visualizing and Exporting Logs
  10. License

Features

  • Multiple log levels (Debug, Info, Warning, Error, Critical)
  • Customizable log categories
  • In-memory and persistent storage of logs
  • Log rotation and archiving
  • Crash log capture
  • Comprehensive log viewer with filtering and sorting capabilities
  • SwiftUI and UIKit compatibility
  • Thread-safe logging operations

Requirements

  • iOS 14.0+
  • Swift 5.10+

Installation

Swift Package Manager

Add the following dependency to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/thepearl/Echo.git", from: "1.0.0")
]

Usage

Basic Logging

import Echo

let logger = Echo.Logger()
logger.log(.info, category: .network, message: "API request started")
logger.log(.error, category: .database, message: "Failed to save data")

Custom Configuration

let config = Echo.LoggerConfiguration(
    minimumLogLevel: .debug,
    maxLogEntries: 5000,
    logRotationInterval: 86400 // 24 hours
)
let logger = Echo.Logger(configuration: config)

Configuration Options

The following table explains the available configuration options for Echo:

Option Type Default Description Progress
minimumLogLevel LogLevel .debug The minimum severity level of logs to be captured. Logs below this level will be ignored. βœ…
maxLogEntries Int 10000 The maximum number of log entries to keep in memory and storage. βœ…
logRotationInterval TimeInterval 86400 (24 hours) The time interval in seconds after which logs are rotated (archived and cleared). βœ…
activeTimeRange ClosedRange? nil An optional time range during which logging is active. If nil, logging is always active. βœ…
persistenceStrategy PersistenceStrategy .fileSystem Defines how logs are persisted. Options include .fileSystem, .coreData, or .inMemory. 🚧
encryptionKey String? nil An optional encryption key for securing stored logs. If provided, logs will be encrypted at rest. 🚧
compressionEnabled Bool false If true, logs will be compressed before storage to save space. 🚧
networkLogOptions NetworkLogOptions .all Configures what network-related information to log (e.g., headers, body, response). 🚧
customFields [String: Any] [:] Additional custom fields to include with each log entry. 🚧

SwiftUI Integration

struct ContentView: View {
    @StateObject private var logger = Echo.Logger()

    var body: some View {
        NavigationView {
            Text("Hello, World!")
                .logPageAppearance(pageName: "ContentView")
        }
        .environmentObject(logger)
    }
}

UIKit Integration

class ViewController: UIViewController {
    let logger = Echo.Logger()

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        logPageAppearance(logger: logger, pageName: "ViewController")
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        logPageDisappearance(logger: logger, pageName: "ViewController")
    }
}

Built-in Log Viewer

Echo provides a built-in log viewer for easy visualization and analysis of logs within your app:

struct LogViewerScreen: View {
    @StateObject private var logger = Echo.Logger()
    
    var body: some View {
        LogViewer()
            .environmentObject(logger)
    }
}

The Log Viewer interface includes:

  • A navigation bar with "Logs" as the title, and "Filter", sort, and share buttons.
  • A search bar for filtering logs.
  • A list of log entries, each showing:
    • A brief description of the log message
    • A category tag (e.g., "Database", "Business Logic", "Authentication")
    • A severity level tag (e.g., "warning", "critical", "error", "debug", "info")
    • A timestamp for each log entry

This interface allows for easy browsing, searching, and analysis of logs directly within your app.

Visualizing and Exporting Logs

Echo provides built-in capabilities for visualizing logs directly within your app and exporting them for further analysis by developers.

In-App Log Visualization

The LogViewer component offers a comprehensive interface for viewing, filtering, and analyzing logs directly within your app. Key features include:

  • Real-time log display
  • Filtering by log level, category, and date range
  • Full-text search across log messages
  • Detailed view for individual log entries

Exporting Logs for Analysis

Echo makes it easy to export logs for offline analysis or sharing with your development team:

let logger = Echo.Logger()

// Export logs as a formatted string
let exportedLogs = logger.exportLogs()

// Share logs using UIActivityViewController
let activityVC = UIActivityViewController(activityItems: [exportedLogs], applicationActivities: nil)
present(activityVC, animated: true)

Exported logs can be:

  • Shared via email, messaging apps, or cloud storage
  • Imported into analysis tools or spreadsheets
  • Used for debugging sessions or bug reports

Advanced Visualization and Analysis

For more advanced visualization and analysis, there is work in progress to consider these approaches:

  1. Expand LogConfiguratons Add some more configurations (mentionned in the table) to make Echo even more flexible to work with.
  2. Custom Dashboards: Create custom SwiftUI views to visualize log data in charts or graphs that can be opened in mac-os.
  3. Integration with Analytics Tools: Export logs in a format compatible with popular analytics platforms.
  4. Automated Reports: Set up automated processes to generate daily or weekly log summaries for your development team.

By leveraging these visualization and export features, Echo will enable developers and testers to gain deeper insights into app behavior, streamline debugging processes, and facilitate effective communication within development teams.

License

Echo is available under the MIT license. See the LICENSE file for more info.

About

Echo: A flexible and lightweight logger with in-app visualiser for Swift iOS applications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%