-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from getditto/we/updateLogExporter
Update LogExporter to use new DittoLogger.export() api
- Loading branch information
Showing
6 changed files
with
104 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
// | ||
// DittoLogManager.swift | ||
// | ||
// | ||
// Created by Walker Erekson on 1/13/23. | ||
// Copyright © 2021 DittoLive Incorporated. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
#if canImport(MessageUI) | ||
import MessageUI | ||
#endif | ||
import UIKit | ||
import DittoSwift | ||
|
||
private struct Config { | ||
static let logsDirectoryName = "debug-logs" | ||
static let zippedLogFileName = "DittoLogs.zip" | ||
static let logFileName = "logs.txt" | ||
static let zippedLogFileName = "ditto.jsonl.gz" | ||
|
||
/// Directory into which debug logs are to be stored. We use a dedicated | ||
/// directory to keep logs grouped (in the event that we begin generating | ||
/// more than one log - either from multiple sub-systems or due to log | ||
/// rotation). | ||
static var logsDirectory: URL! = { | ||
let directory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first! | ||
return directory.appendingPathComponent(logsDirectoryName, isDirectory: true) | ||
}() | ||
|
||
/// A temporary location into which we can store zipped logs before sharing | ||
/// them via a share sheet. | ||
static var zippedLogsURL: URL! = { | ||
let directory = FileManager.default.temporaryDirectory | ||
return directory.appendingPathComponent(Config.zippedLogFileName) | ||
}() | ||
|
||
} | ||
|
||
public struct DittoLogManager { | ||
public static let shared = DittoLogManager() | ||
/// LogManager acts as a thin interface over our stored log files and | ||
/// offers functionality to share zipped logs with an iOS share sheet. | ||
struct LogManager { | ||
|
||
private init() {} | ||
// MARK: - Singleton | ||
|
||
public func createLogsZip() -> URL? { | ||
try? FileManager().removeItem(at: Config.zippedLogsURL) | ||
public static let shared = LogManager() | ||
|
||
let coordinator = NSFileCoordinator() | ||
var nsError: NSError? | ||
// MARK: - Initialization | ||
|
||
// Runs synchronously, so no need to co-ordinate multiple callers | ||
coordinator.coordinate(readingItemAt: Config.logsDirectory, | ||
options: [.forUploading], error: &nsError) { tempURL in | ||
do { | ||
try FileManager().moveItem(at: tempURL, to: Config.zippedLogsURL) | ||
} catch let error { | ||
assertionFailure("Failed to move zipped logs into location: \(error)") | ||
} | ||
} | ||
private init() { | ||
// Private singleton constructor | ||
} | ||
|
||
if let error = nsError { | ||
assertionFailure("Failed to zip logs: \(error)") | ||
return nil | ||
} | ||
// MARK: - Functions | ||
|
||
/// Zips all contents in our log directory, placing an updated zip file at URL returned. | ||
public func exportLogs() async throws -> URL { | ||
try? FileManager().removeItem(at: Config.zippedLogsURL) | ||
try await DittoLogger.export(to: Config.zippedLogsURL) | ||
return Config.zippedLogsURL | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters