LogItUI 0.2.0

LogItUI 0.2.0

Maintained by Jake Prickett.



 
Depends on:
SnapKit< 6, >= 5.0.1
LogIt= 0.2.0
 

LogItUI 0.2.0

  • By
  • Jake Prickett


Written By: Jake Prickett🖋


Build Status Swift 5
CocoaPods Carthage Swift Package Manager
Platform LICENSE

Elevator Pitch

Since the introduction of the Swift Logging Framework one aspect was missing for me that seemed crucial for day to day iOS engineers: the ability to view the logs from within the application. Without having to manually connect a device to a computer or bring in the device. This respository contains two frameworks: a purely Swift logging library, and a companion User Interface Library for viewing stored and generated logs.

This library was inspired by the Swift Logging Framework by Apple.

LogIt

LogIt is a lightweight logging library for iOS & macOS applications written in Swift that efficiently writes and stores logs on devices. By doing this, it provides access to those Logs from your code without the need of connecting the device to a computer.

LogItUI

LogItUI, the companion library to LogIt, is a library that supports displaying of logs recorded with LogIt for iOS applications. (note: macOS UI support is part of the feature roadmap) That doesn't quite meet your needs? LogIt also provides the capability of building your own UI around the logs for more custom use cases.

Basic Usage

LogIt

Configuration

The first step with using LogIt is to configure your logger properly. This value tell the library where to store the log files and is a required step.

Note: This is typically best done in your AppDelegate or SceneDelegate.

// Custom specified identifier
LogIt.configure(with: .custom('custom.log.identifier'))

// Pulls the bundleId if available
LogIt.configure(with: .bundleId)

// Default value: "LogIt.log"
LogIt.configure(with: .default)

If desired, this file path can be accessed using the LogIt.logFileURL.

In order to properly log, the framework must be explicity enabled using the following methods:

// Enables logging
LogIt.enableLogging()

// Disables logging
LogIt.disableLogging()
Log Levels

The following log levels are supported:

Log Level Value
Error .error
Warning .warning
Informational .info

If you would like to only log messages above a certain level:

// Will only display logs that are more severe or equal to `.warning`
// (All `.warning` logs and `.error` logs currently.)
LogIt.setLogLevel(.warning)

This might be useful in certain situations such as an App Store release where it might not be helpful to have robust informational logging.

Logging

Now onto the fun part, Logging. There is an associated method for each log level. This method takes in a string.

LogIt.info("Informational Log!")

LogIt.warning("Warning Log!")

LogIt.error("Error Log!")

Yes, it's that easy!

Retrieving Logs

Logs can be retrieved by calling the LogIt.getLogs() method. In the event that an error occurs while fetching, this method will throw a descriptive error that can be handled.

It also will also clear the log file in the event that the data has been corrupted or the file is no longer stored on disc.

Clearing Logs

Logs can be cleared by calling the LogIt.clearLogs() method. In the event that an error occurs while clearing, this method will throw a descriptive error.

LogItUI

The main component of LogItUI is the LogItViewController. This is respnosible for fetching, displaying, and filtering logs.

View Demo
@objc
private func viewLogs() {
  let vc = LogItViewController()
  navigationController?.present(vc, animated: true, completion: nil)
}

Installation

Please reference the below instructions for installing LogIt and LogItUI.

Requirements

  • iOS 12.0+
  • macOS 10.12+
  • Swift 5.0+

CocoaPods

To install it, simply add the following line to your Podfile :

# To consume LogIt
pod 'LogIt'
# To consume LogItUI
pod 'LogItUI'

Carthage

To install it, simply add the following line to your Cartfile:

github "Jake-Prickett/LogIt"

Swift Package Manager

To install it, simply add the package as a dependency in

Package.swift:

dependencies: [
  .package(url: "https://github.com/Jake-Prickett/LogIt.git", from: "X.Y.Z"),
]

Feature Roadmap

  • Finalize interface/configuration steps
  • Out of the box LogItViewController with customizable options
  • Add ability to configure with specified identifier for log file (handle multiple loggers on one device)
  • Ability to export logs via LogItViewController (Email initially)
  • Support Dark Mode for LogItViewController
  • Break up into LogIt and LogItUI frameworks (don't require consumer to use both unless they want)
  • Add CI Runs for PRs
  • Add SwiftPM & CocoaPod Support
  • Unit test coverage
  • Documentation (Badges, Finalize description, Features, Basic Usage, Dependency Support)
  • Code Documentation
  • Set minimum log level desired
  • Alternate background color for rows in the VC
  • Introduce thread safe reading/writing
  • Log to a buffer (of configurable size) that writes when limit reached. (vs. writing every log, can get expensive)
  • Add metadata that can be passed when logging
  • When selecting a log, view more details for that particular log
  • Search functionality for logs
  • Advanced Usage: Out of the ViewController not enough? Expose raw log file for consumer with instructions on how to use it.

If you notice issues or have feature requests - please feel free to open an issue leveraging the corresponding template. Feel like fixing it yourself and want to get involved? Please do!