Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

MakeupStudio/LoggingKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple logging kit written in Swift, based on apple/swift-log framework.

Usage

  1. Bootstrap logging system globally
// AppDelegate.swift
import LoggingKit
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    static let logs = Box<[Log]>()
    func application(..., didFinishLaunchingWithOptions...) -> Bool {
        LoggingSystem.bootstrap(level: .info, output: Self.logs)
    }
    // ...
}
  1. Passthrough convenience types
// LoggingKit.swift
import LoggingKit

typealias Loggable = LoggingKit.Loggable
typealias Log = LoggingKit.Log
  1. Log
class ProfileViewModel: Loggable {
    // ...
    func logout() {
        userManager.logout(
            onSuccess: { [weak self] in
                self?.coordinator.go(to: .signIn)
                Self.logger.trace("User signed out.")
            }, 
            onFailure: { [weak self] error in
                Self.logger.trace("User logout failed.")
                Self.logger.info(.dump(error))
            })
    }
}
  1. Grab logs
class LoggingViewModel {
    var logs: [Log] { AppDelegate.logs.content }
}
  1. See Examples for more.

Installation

Add the package to Your SwiftPM package dependencies:

.package(
    url: "https://github.com/MakeupStudio/LoggingKit.git", 
    .upToNextMajor(from: "1.0.0-beta.1.1")
)

then add LoggingKit dependency to your target.