Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios: fix passing of file, line, and function arguments #105

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading