Skip to content

Commit

Permalink
ios: fix passing of file, line, and function arguments (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Augustyniak authored Nov 7, 2024
1 parent f9172d5 commit 478eaa2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
9 changes: 6 additions & 3 deletions platform/swift/source/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ public final class Logger {
func log(
level: LogLevel,
message: @autoclosure () -> String,
file _: String? = #file,
line _: Int? = #line,
function _: String? = #function,
file: String? = #file,
line: Int? = #line,
function: String? = #function,
fields: Fields? = nil,
matchingFields: Fields? = nil,
error: Error? = nil,
Expand All @@ -252,6 +252,9 @@ public final class Logger {
self.underlyingLogger.log(
level: level,
message: message(),
file: file,
line: line,
function: function,
fields: fields,
matchingFields: matchingFields,
error: error,
Expand Down
21 changes: 18 additions & 3 deletions test/platform/swift/unit_integration/core/LoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ final class LoggerTests: XCTestCase {
XCTAssertEqual(bridge.logs.count, 1)
let log = bridge.logs[0]

var logFields = try XCTUnwrap(log.fields?.toDictionary())
XCTAssertNotNil(logFields.removeValue(forKey: "_file"))
XCTAssertNotNil(logFields.removeValue(forKey: "_line"))
XCTAssertNotNil(logFields.removeValue(forKey: "_function"))

XCTAssertEqual(log.level, .debug)
XCTAssertEqual(log.message, "test")
self.assertEqual(
Expand All @@ -170,7 +175,7 @@ final class LoggerTests: XCTestCase {
"_error_details": String(describing: error),
"foo": "bar",
],
try XCTUnwrap(log.fields)
logFields
)
}

Expand Down Expand Up @@ -198,6 +203,11 @@ final class LoggerTests: XCTestCase {
XCTAssertEqual(bridge.logs.count, 1)
let log = bridge.logs[0]

var logFields = try log.fields?.toDictionary()
XCTAssertNotNil(logFields?.removeValue(forKey: "_file"))
XCTAssertNotNil(logFields?.removeValue(forKey: "_line"))
XCTAssertNotNil(logFields?.removeValue(forKey: "_function"))

XCTAssertEqual(log.message, "HTTPRequest")
XCTAssertEqual(log.level, .debug)
XCTAssertEqual(log.type, .span)
Expand All @@ -208,7 +218,7 @@ final class LoggerTests: XCTestCase {
"_span_id": requestInfo.spanID,
"_query": "bar",
"foo": "bar",
], try XCTUnwrap(log.fields?.toDictionary()))
], logFields)
XCTAssertTrue(try XCTUnwrap(log.matchingFields?.toDictionary()).isEmpty)
}

Expand Down Expand Up @@ -247,6 +257,11 @@ final class LoggerTests: XCTestCase {
XCTAssertEqual(bridge.logs.count, 1)
let log = bridge.logs[0]

var logFields = try log.fields?.toDictionary()
XCTAssertNotNil(logFields?.removeValue(forKey: "_file"))
XCTAssertNotNil(logFields?.removeValue(forKey: "_line"))
XCTAssertNotNil(logFields?.removeValue(forKey: "_function"))

XCTAssertEqual(log.message, "HTTPResponse")
XCTAssertEqual(log.level, .debug)
XCTAssertEqual(log.type, .span)
Expand All @@ -260,7 +275,7 @@ final class LoggerTests: XCTestCase {
"_status_code": "200",
"_query": "bar",
"foo": "bar",
], try log.fields?.toDictionary())
], logFields)
XCTAssertEqual([
"_request.foo": "bar",
"_request._host": "api.bitdrift.io",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ extension UploadedLog {
$0.key < $1.key
})

let sortedSelf = self.fields.sorted(by: { $0.key < $1.key })
var sortedSelf = self.fields.sorted(by: { $0.key < $1.key })
sortedSelf.removeAll { ["_file", "_line", "_function"].contains($0.key) }

XCTAssertEqual(fields, sortedSelf)
}
Expand Down

0 comments on commit 478eaa2

Please sign in to comment.