Git Product home page Git Product logo

swiftlogfirecloud's Introduction

SwiftLogFireCloud Firebase Extension

This library can be used as an implementation of Apple's SwiftLog interface that captures console logs from iOS and (TODO: macOS) apps and pushes them to Firebase Cloud Storage as flat files for later review. This library is often helpful for temperal data investigations over event based logging investigations. It is implemented with the inherent bias to retain a positive user experience of the client app and therefore opts to lose logs over consuming bandwidth or excessive retry failure processing. Controlling whether the library will log to the cloud can be managed by the client app and even remotely via a Firestore doc listener, an exercise left to the reader.

This is not an officially supported Google product.

How to add SwiftLogFireCloud to your app

  1. In your Xcode project, select File -> Swift Packages -> Add Package Dependencies

  2. Enter https://github.com/google/swiftlogfirecloud into the search bar.

  3. Select master as branch or appropriate version for your needs

  4. Add and initialize Firebase in your project, if not already done. See https://firebase.google.com/docs/ios/setup

  5. Create a object in your app that conforms to CloudFileUploaderProtocol and implements the uploadFile method as such:

       import Foundation
       import Firebase
       import SwiftLogFireCloud
    
       final class SwiftLogFireCloudUploader : CloudFileUploaderProtocol {
    
     	private let storage: Storage
    
       	init(storage: Storage) {
     	  self.storage = storage
     	}
    
       func uploadFile(from localFile: LocalLogFile, to cloudPath: String, completion: @escaping (Result<LocalLogFile, CloudUploadError>) -> Void) {
    
     	let storageReference = self.storage.reference()
     	let cloudReference = storageReference.child(cloudPath)
     	let uploadTask = cloudReference.putFile(from: localFile.fileURL, metadata: nil) { metadata, error in
     	  if let error = error {
     		print(error.localizedDescription)
     		completion(.failure(CloudUploadError.failedToUpload(localFile)))
       	  }
       	}
     	_ = uploadTask.observe(.success) { snapshot in
     	  completion(.success(localFile))
       	}
     	_ = uploadTask.observe(.failure) { snapshot in
     	  completion(.failure(CloudUploadError.failedToUpload(localFile)))
       	}
       }
     }
    
  6. In your AppDelegate add import Logging and import SwiftLogFireCloud

  7. In your AppDelegate method didFinishLaunchingWithOptions add the following :

     //Create the client impl of the FirebaseStorage uploader
     logUploader = SwiftLogFireCloudUploader(storage: Storage.storage())
    
     //Configure and initialize the SwiftLogFireCloud library
     let config = SwiftLogFireCloudConfig(
       logToCloud: true,
       localFileSizeThresholdToPushToCloud: 1024*1024*3,
       logToCloudOnSimulator: false,
       cloudUploader: logUploader)
     let swiftLogFileCloudManager = SwiftLogFileCloudManager()
    
     //Bootstrap SwiftLog...make sure this is only run once
     LoggingSystem.bootstrap(swiftLogFileCloudManager.makeLogHandlerFactory(config: config))
    
     //Create a logger
     logger = Logger(label: "SwiftLogFireCloudExampleAppLogger")
    
  8. And lastly, wherever in your code you want to log, add import Logging and log as such: logger?.info("I am a log message")

The sample project SwiftLogFireCloudExampleApp in the depot demonstrates a working client app logging using SwiftLog.

A note about privacy

The SwiftLog interface was apparently originally designed for Swift on the Server, as such there is no integration of SwiftLog with OSLog on Apple platforms. As such, it is imperative that client app developers use descretion when using SwiftLogFireCloud and not log personally identifiable information with SwiftLogFireCloud from client devices which will reach your Firebase Storage buckets.

Warning

This library violates the fundamental rule of software engineering: never let the software engineering manager write code. Caveat emptor.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0

swiftlogfirecloud's People

Contributors

leisurehound avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

swiftlogfirecloud's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.