Merge branch 'test-file-logging'
This commit is contained in:
commit
786d5d2782
|
@ -55,7 +55,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
if AppConstants.Flags.isBeta {
|
||||
model.add(.test)
|
||||
model.setHeader("Beta", for: .test)
|
||||
model.set([.testTermination], in: .test)
|
||||
model.set([.testDisplayLog, .testTermination], in: .test)
|
||||
}
|
||||
return model
|
||||
}()
|
||||
|
@ -241,6 +241,17 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
|||
UIApplication.shared.open(AppConstants.URLs.subreddit, options: [:], completionHandler: nil)
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
private func testDisplayLog() {
|
||||
guard let log = try? String(contentsOf: AppConstants.Log.fileURL) else {
|
||||
return
|
||||
}
|
||||
let alert = Macros.alert("Debug log", log)
|
||||
alert.addCancelAction(L10n.Global.ok)
|
||||
present(alert, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
private func testTermination() {
|
||||
exit(0)
|
||||
}
|
||||
|
@ -271,6 +282,8 @@ extension OrganizerViewController {
|
|||
case openAbout
|
||||
|
||||
case uninstall
|
||||
|
||||
case testDisplayLog
|
||||
|
||||
case testTermination
|
||||
}
|
||||
|
@ -340,9 +353,14 @@ extension OrganizerViewController {
|
|||
cell.caption = L10n.Organizer.Cells.Uninstall.caption
|
||||
return cell
|
||||
|
||||
case .testDisplayLog:
|
||||
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
||||
cell.leftText = "Display current log"
|
||||
return cell
|
||||
|
||||
case .testTermination:
|
||||
let cell = Cells.destructive.dequeue(from: tableView, for: indexPath)
|
||||
cell.caption = "Terminate app"
|
||||
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
|
||||
cell.leftText = "Terminate app"
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
@ -365,6 +383,9 @@ extension OrganizerViewController {
|
|||
case .uninstall:
|
||||
confirmVpnProfileDeletion()
|
||||
|
||||
case .testDisplayLog:
|
||||
testDisplayLog()
|
||||
|
||||
case .testTermination:
|
||||
testTermination()
|
||||
}
|
||||
|
|
|
@ -86,17 +86,37 @@ class AppConstants {
|
|||
}
|
||||
|
||||
class Log {
|
||||
static let level: SwiftyBeaver.Level = .debug
|
||||
|
||||
static let debugFormat = "$DHH:mm:ss$d - $M"
|
||||
|
||||
static var debugSnapshot: () -> String = { TransientStore.shared.service.vpnLog }
|
||||
|
||||
static let viewerRefreshInterval: TimeInterval = 3.0
|
||||
|
||||
private static let fileName = "Debug.log"
|
||||
|
||||
static var fileURL: URL {
|
||||
return FileManager.default.userURL(for: .cachesDirectory, appending: fileName)
|
||||
}
|
||||
|
||||
private static let console: ConsoleDestination = {
|
||||
let dest = ConsoleDestination()
|
||||
dest.minLevel = level
|
||||
dest.useNSLog = true
|
||||
return dest
|
||||
}()
|
||||
|
||||
private static let file: FileDestination = {
|
||||
let dest = FileDestination()
|
||||
dest.minLevel = level
|
||||
dest.logFileURL = fileURL
|
||||
return dest
|
||||
}()
|
||||
|
||||
static func configure() {
|
||||
let console = ConsoleDestination()
|
||||
console.useNSLog = true
|
||||
console.minLevel = .debug
|
||||
SwiftyBeaver.addDestination(console)
|
||||
SwiftyBeaver.addDestination(file)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue