Move tracing configuration to the rust side.

This commit is contained in:
Stefan Ceriu
2025-01-09 13:23:14 +02:00
committed by Stefan Ceriu
parent 2671d90bc1
commit 57b85d2650
14 changed files with 100 additions and 244 deletions
+12 -12
View File
@@ -15,12 +15,12 @@ class LoggingTests: XCTestCase {
}
override func setUpWithError() throws {
RustTracing.deleteLogFiles()
Tracing.deleteLogFiles()
}
func testLogging() async throws {
let target = "tests"
XCTAssertTrue(RustTracing.logFiles.isEmpty)
XCTAssertTrue(Tracing.logFiles.isEmpty)
MXLog.configure(currentTarget: target, filePrefix: target, logLevel: .info)
@@ -43,7 +43,7 @@ class LoggingTests: XCTestCase {
MXLog.info(infoLog)
guard let logFile = RustTracing.logFiles.first else {
guard let logFile = Tracing.logFiles.first else {
XCTFail(Constants.genericFailure)
return
}
@@ -55,7 +55,7 @@ class LoggingTests: XCTestCase {
let verboseLog = UUID().uuidString
MXLog.verbose(verboseLog)
guard let logFile = RustTracing.logFiles.first else {
guard let logFile = Tracing.logFiles.first else {
XCTFail(Constants.genericFailure)
return
}
@@ -65,7 +65,7 @@ class LoggingTests: XCTestCase {
func validateTargetName(_ target: String) throws {
MXLog.info(UUID().uuidString)
guard let logFile = RustTracing.logFiles.first else {
guard let logFile = Tracing.logFiles.first else {
XCTFail(Constants.genericFailure)
return
}
@@ -100,7 +100,7 @@ class LoggingTests: XCTestCase {
MXLog.info(roomSummary)
// Then the log file should not include the sensitive information
guard let logFile = RustTracing.logFiles.first else {
guard let logFile = Tracing.logFiles.first else {
XCTFail(Constants.genericFailure)
return
}
@@ -188,7 +188,7 @@ class LoggingTests: XCTestCase {
MXLog.info(fileMessage)
// Then the log file should not include the text content
guard let logFile = RustTracing.logFiles.first else {
guard let logFile = Tracing.logFiles.first else {
XCTFail(Constants.genericFailure)
return
}
@@ -255,7 +255,7 @@ class LoggingTests: XCTestCase {
MXLog.info(rustFileMessage)
// Then the log file should not include the text content
guard let logFile = RustTracing.logFiles.first else {
guard let logFile = Tracing.logFiles.first else {
XCTFail(Constants.genericFailure)
return
}
@@ -282,10 +282,10 @@ class LoggingTests: XCTestCase {
func testLogFileSorting() async throws {
// Given a collection of log files.
XCTAssertTrue(RustTracing.logFiles.isEmpty)
XCTAssertTrue(Tracing.logFiles.isEmpty)
// When creating new logs.
let logsFileDirectory = RustTracing.logsDirectory
let logsFileDirectory = Tracing.logsDirectory
for i in 1...5 {
let filename = "console.\(i).log"
try "console".write(to: logsFileDirectory.appending(path: filename), atomically: true, encoding: .utf8)
@@ -297,7 +297,7 @@ class LoggingTests: XCTestCase {
}
// Then the logs should be sorted chronologically (newest first) and not alphabetically.
XCTAssertEqual(RustTracing.logFiles.map(\.lastPathComponent),
XCTAssertEqual(Tracing.logFiles.map(\.lastPathComponent),
["console-nse.5.log",
"console-nse.4.log",
"console-nse.3.log",
@@ -317,7 +317,7 @@ class LoggingTests: XCTestCase {
try fileHandle.close()
// Then that file should now be the first log file.
XCTAssertEqual(RustTracing.logFiles.map(\.lastPathComponent),
XCTAssertEqual(Tracing.logFiles.map(\.lastPathComponent),
["console.1.log",
"console-nse.5.log",
"console-nse.4.log",
@@ -1,44 +0,0 @@
//
// Copyright 2022-2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import XCTest
@testable import ElementX
class TracingConfigurationTests: XCTestCase {
func testConfiguration() { // swiftlint:disable line_length
var filter = TracingConfiguration(logLevel: .error, currentTarget: "tests", filePrefix: nil).filter
XCTAssertEqual(filter, "hyper=warn,matrix_sdk_ffi=info,matrix_sdk::client=trace,matrix_sdk_crypto=debug,matrix_sdk_crypto::olm::account=trace,matrix_sdk::oidc=trace,matrix_sdk::http_client=debug,matrix_sdk::sliding_sync=info,matrix_sdk_base::sliding_sync=info,matrix_sdk_ui::timeline=info,matrix_sdk::event_cache=info,matrix_sdk_sqlite::event_cache_store=info,tests=error")
filter = TracingConfiguration(logLevel: .warn, currentTarget: "tests", filePrefix: nil).filter
XCTAssertEqual(filter, "hyper=warn,matrix_sdk_ffi=info,matrix_sdk::client=trace,matrix_sdk_crypto=debug,matrix_sdk_crypto::olm::account=trace,matrix_sdk::oidc=trace,matrix_sdk::http_client=debug,matrix_sdk::sliding_sync=info,matrix_sdk_base::sliding_sync=info,matrix_sdk_ui::timeline=info,matrix_sdk::event_cache=info,matrix_sdk_sqlite::event_cache_store=info,tests=warn")
filter = TracingConfiguration(logLevel: .info, currentTarget: "tests", filePrefix: nil).filter
XCTAssertEqual(filter, "hyper=warn,matrix_sdk_ffi=info,matrix_sdk::client=trace,matrix_sdk_crypto=debug,matrix_sdk_crypto::olm::account=trace,matrix_sdk::oidc=trace,matrix_sdk::http_client=debug,matrix_sdk::sliding_sync=info,matrix_sdk_base::sliding_sync=info,matrix_sdk_ui::timeline=info,matrix_sdk::event_cache=info,matrix_sdk_sqlite::event_cache_store=info,tests=info")
filter = TracingConfiguration(logLevel: .debug, currentTarget: "tests", filePrefix: nil).filter
XCTAssertEqual(filter, "hyper=warn,matrix_sdk_ffi=debug,matrix_sdk::client=trace,matrix_sdk_crypto=debug,matrix_sdk_crypto::olm::account=trace,matrix_sdk::oidc=trace,matrix_sdk::http_client=debug,matrix_sdk::sliding_sync=debug,matrix_sdk_base::sliding_sync=debug,matrix_sdk_ui::timeline=debug,matrix_sdk::event_cache=debug,matrix_sdk_sqlite::event_cache_store=debug,tests=debug")
filter = TracingConfiguration(logLevel: .trace, currentTarget: "tests", filePrefix: nil).filter
XCTAssertEqual(filter, "hyper=warn,matrix_sdk_ffi=trace,matrix_sdk::client=trace,matrix_sdk_crypto=trace,matrix_sdk_crypto::olm::account=trace,matrix_sdk::oidc=trace,matrix_sdk::http_client=trace,matrix_sdk::sliding_sync=trace,matrix_sdk_base::sliding_sync=trace,matrix_sdk_ui::timeline=trace,matrix_sdk::event_cache=trace,matrix_sdk_sqlite::event_cache_store=trace,tests=trace")
} // swiftlint:enable line_length
func testLevelOrdering() {
var logLevels: [TracingConfiguration.LogLevel] = [.info, .error, .trace, .debug, .warn]
XCTAssertEqual(logLevels.sorted(), [.error, .warn, .info, .debug, .trace])
logLevels = [.warn, .error, .debug, .trace, .info, .error]
XCTAssertEqual(logLevels.sorted(), [.error, .error, .warn, .info, .debug, .trace])
}
}