mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Structured logging (#831)
* Structured logging support * Bump the SDK, fix breaking changes * Enabled more logging of timeline diffs * Keep only source file last path components in logs * Bump the SDK, tweaks following code review
This commit is contained in:
@@ -36,9 +36,8 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
let log = UUID().uuidString
|
||||
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration)
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
|
||||
MXLog.info(log)
|
||||
guard let logFile = MXLogger.logFiles.first else {
|
||||
XCTFail(Constants.genericFailure)
|
||||
@@ -56,9 +55,7 @@ class LoggingTests: XCTestCase {
|
||||
// When launching the app 5 times.
|
||||
let launchCount = 5
|
||||
for index in 0..<launchCount {
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration) // This call is only made at app launch.
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
MXLog.info("Launch \(index + 1)")
|
||||
}
|
||||
|
||||
@@ -77,10 +74,7 @@ class LoggingTests: XCTestCase {
|
||||
let launchCount = 10
|
||||
let logFileCount = 5
|
||||
for index in 0..<launchCount {
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.maxLogFilesCount = UInt(logFileCount)
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration) // This call is only made at app launch.
|
||||
MXLog.configure(redirectToFiles: true, maxLogFileCount: UInt(logFileCount))
|
||||
MXLog.info("Launch \(index + 1)")
|
||||
}
|
||||
|
||||
@@ -97,12 +91,9 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
// When launching the app 10 times, with a max total log size of 25KB and logging ~5KB data each time.
|
||||
let launchCount = 10
|
||||
let logFileSizeLimit = 25 * 1024
|
||||
let logFileSizeLimit: UInt = 25 * 1024
|
||||
for index in 0..<launchCount {
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.logFilesSizeLimit = UInt(logFileSizeLimit)
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration) // This call is only made at app launch.
|
||||
MXLog.configure(redirectToFiles: true, logFileSizeLimit: logFileSizeLimit)
|
||||
MXLog.info("Launch \(index + 1)")
|
||||
|
||||
// Add ~5KB of logs
|
||||
@@ -142,11 +133,9 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
let log = UUID().uuidString
|
||||
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.logLevel = .error
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration)
|
||||
MXLog.info(log)
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
|
||||
MXLog.verbose(log)
|
||||
guard let logFile = MXLogger.logFiles.first else {
|
||||
XCTFail(Constants.genericFailure)
|
||||
return
|
||||
@@ -159,19 +148,17 @@ class LoggingTests: XCTestCase {
|
||||
func testSubLogName() {
|
||||
XCTAssert(MXLogger.logFiles.isEmpty)
|
||||
|
||||
let subLogName = "nse"
|
||||
let target = "nse"
|
||||
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.subLogName = subLogName
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration)
|
||||
MXLog.configure(target: target, redirectToFiles: true)
|
||||
|
||||
MXLog.info(UUID().uuidString)
|
||||
guard let logFile = MXLogger.logFiles.first else {
|
||||
XCTFail(Constants.genericFailure)
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertTrue(logFile.lastPathComponent.contains(subLogName))
|
||||
XCTAssertTrue(logFile.lastPathComponent.contains(target))
|
||||
}
|
||||
|
||||
func testRoomSummaryContentIsRedacted() throws {
|
||||
@@ -189,10 +176,9 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
// When logging that value
|
||||
XCTAssert(MXLogger.logFiles.isEmpty)
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.logLevel = .info
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration)
|
||||
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
|
||||
MXLog.info(roomSummary)
|
||||
|
||||
// Then the log file should not include the sensitive information
|
||||
@@ -207,7 +193,6 @@ class LoggingTests: XCTestCase {
|
||||
XCTAssertFalse(content.contains(lastMessage))
|
||||
}
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
func testTimelineContentIsRedacted() throws {
|
||||
// Given timeline items that contain text
|
||||
let textAttributedString = "TextAttributed"
|
||||
@@ -235,10 +220,9 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
// When logging that value
|
||||
XCTAssert(MXLogger.logFiles.isEmpty)
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.logLevel = .info
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration)
|
||||
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
|
||||
MXLog.info(textMessage)
|
||||
MXLog.info(noticeMessage)
|
||||
MXLog.info(emoteMessage)
|
||||
@@ -294,10 +278,9 @@ class LoggingTests: XCTestCase {
|
||||
|
||||
// When logging that value
|
||||
XCTAssert(MXLogger.logFiles.isEmpty)
|
||||
let configuration = MXLogConfiguration()
|
||||
configuration.logLevel = .info
|
||||
configuration.redirectLogsToFiles = true
|
||||
MXLog.configure(configuration)
|
||||
|
||||
MXLog.configure(redirectToFiles: true)
|
||||
|
||||
MXLog.info(textMessage)
|
||||
MXLog.info(noticeMessage)
|
||||
MXLog.info(emoteMessage)
|
||||
|
||||
@@ -95,7 +95,7 @@ private class MockMediaLoadingClient: ClientProtocol {
|
||||
|
||||
func uploadMedia(mimeType: String, data content: [UInt8]) throws -> String { fatalError() }
|
||||
|
||||
func getMediaFile(source: MatrixRustSDK.MediaSource, mimeType: String) throws -> MatrixRustSDK.MediaFileHandle { fatalError() }
|
||||
func getMediaFile(mediaSource: MatrixRustSDK.MediaSource, mimeType: String) throws -> MatrixRustSDK.MediaFileHandle { fatalError() }
|
||||
|
||||
func getProfile(userId: String) throws -> MatrixRustSDK.UserProfile { fatalError() }
|
||||
|
||||
@@ -129,10 +129,6 @@ private class MockMediaLoadingClient: ClientProtocol {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
func searchUsers(searchTerm: String, limit: UInt64) throws -> MatrixRustSDK.SearchUsersResults {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
func unignoreUser(userId: String) throws {
|
||||
fatalError()
|
||||
}
|
||||
@@ -146,4 +142,6 @@ private class MockMediaLoadingClient: ClientProtocol {
|
||||
lang: String) throws {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
func searchUsers(searchTerm: String, limit: UInt64) throws -> MatrixRustSDK.SearchUsersResults { fatalError() }
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ private struct MockEventTimelineItem: EventTimelineItemProtocol {
|
||||
|
||||
func raw() -> String? { nil }
|
||||
|
||||
func reactions() -> [MatrixRustSDK.Reaction]? { nil }
|
||||
func reactions() -> [MatrixRustSDK.Reaction] { [] }
|
||||
|
||||
func sender() -> String { "@user:server.com" }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user