Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #206 from Lickability/hides-logging
Browse files Browse the repository at this point in the history
Hides Default Logging Capabilities on iOS 10+
  • Loading branch information
mbbischoff authored Feb 3, 2017
2 parents d8b942c + c182459 commit 19b6f1a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ final class FeedbackTableViewDataSource: NSObject, UITableViewDataSource {
// MARK: - FeedbackTableViewDataSource

private static func sectionsFromConfiguration(_ interfaceCustomization: InterfaceCustomization, screenshot: UIImage, logSupporting: LogSupporting, userEnabledLogCollection: Bool) -> [Section] {
guard logSupporting.logCollector != nil else { return [] }
var sections: [Section] = []

let screenshotRow = Row.screenshot(screensot: screenshot, hintText: interfaceCustomization.interfaceText.feedbackEditHint, hintFont: interfaceCustomization.appearance.feedbackEditHintFont)
let screenshotSection = Section.feedback(rows: [screenshotRow])

let collectLogsRow = Row.collectLogs(enabled: userEnabledLogCollection, title: interfaceCustomization.interfaceText.logCollectionPermissionTitle, font: interfaceCustomization.appearance.logCollectionPermissionFont, canView: logSupporting.logViewer != nil)
let collectLogsSection = Section.feedback(rows: [collectLogsRow])
sections.append(screenshotSection)

return [screenshotSection, collectLogsSection]
if logSupporting.logCollector != nil {
let collectLogsRow = Row.collectLogs(enabled: userEnabledLogCollection, title: interfaceCustomization.interfaceText.logCollectionPermissionTitle, font: interfaceCustomization.appearance.logCollectionPermissionFont, canView: logSupporting.logViewer != nil)
let collectLogsSection = Section.feedback(rows: [collectLogsRow])

sections.append(collectLogsSection)
}

return sections
}

private func checkmarkCell(for row: Row) -> CheckmarkCell {
Expand Down
14 changes: 13 additions & 1 deletion PinpointKit/PinpointKit/Sources/Core/SystemLogCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ open class SystemLogCollector: LogCollector {

private let logger: ASLLogger

public init(loggingType: LoggingType = .application) {
/**
Creates a new system logger.

- parameter loggingType: Specifies the type of logs to collect.

- warning: This initializer returns `nil` on iOS 10.0+. When running on iOS 10.0+, ASL is superseded by unified logging, for which there are no APIs to search or read log messages.
- seealso: https://developer.apple.com/reference/os/logging
*/
public init?(loggingType: LoggingType = .application) {
if #available(iOS 10.0, *), loggingType == .application {
return nil
}

switch loggingType {
case .application:
logger = ASLLogger(bundleIdentifier: Bundle.main.bundleIdentifier ?? "")
Expand Down
14 changes: 7 additions & 7 deletions PinpointKit/PinpointKitTests/SystemLogCollectorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class SystemLogCollectorTests: XCTestCase {

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(1)) {

let logs = systemLogCollector.retrieveLogs()
let systemLogs = systemLogCollector?.retrieveLogs()

guard let firstLog = logs.first else { return XCTFail("There should be at least 1 log.") }
guard let logs = systemLogs, let firstLog = logs.first else { return XCTFail("There should be at least 1 log.") }

XCTAssertEqual(logs.count, 3)
XCTAssertTrue(firstLog.contains(testString))
Expand All @@ -49,9 +49,9 @@ class SystemLogCollectorTests: XCTestCase {
let expectation = defaultExpectation()

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(1)) {
let logs = systemLogCollector.retrieveLogs()
let systemLogs = systemLogCollector?.retrieveLogs()

guard logs.count == 3 else { return XCTFail("Count should be 3.") }
guard let logs = systemLogs, logs.count == 3 else { return XCTFail("Count should be 3.") }

let firstLog = logs[0]
let secondLog = logs[1]
Expand All @@ -74,14 +74,14 @@ class SystemLogCollectorTests: XCTestCase {

let systemLogCollector = SystemLogCollector(loggingType: .testing)

XCTAssertEqual(systemLogCollector.retrieveLogs().count, 0)
XCTAssertEqual(systemLogCollector?.retrieveLogs().count, 0)
}

func testLogCollectorHasNoLogsInitially() {
let systemLogCollector = SystemLogCollector(loggingType: .testing)

let logs = systemLogCollector.retrieveLogs()
let logs = systemLogCollector?.retrieveLogs()

XCTAssertEqual(logs.count, 0)
XCTAssertEqual(logs?.count, 0)
}
}

0 comments on commit 19b6f1a

Please sign in to comment.