Skip to content

Commit

Permalink
Merge pull request #117 from square/entin/multiline-parameters
Browse files Browse the repository at this point in the history
Improve formatting of multiline parameters
  • Loading branch information
NickEntin authored Mar 18, 2021
2 parents 2bc73df + d8d8141 commit 79deb1f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CoreAardvark.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CoreAardvark'
s.version = '3.0.0'
s.version = '3.0.1'
s.license = 'Apache License, Version 2.0'
s.summary = 'Aardvark is a library that makes it dead simple to create actionable bug reports. Usable by extensions.'
s.homepage = 'https://github.com/square/Aardvark'
Expand Down
5 changes: 4 additions & 1 deletion Sources/CoreAardvark/Logging/ARKLogMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ - (NSString *)description;

NSMutableString *parametersString = [NSMutableString new];
for (NSString *key in [[self.parameters allKeys] sortedArrayUsingSelector:@selector(compare:)]) {
[parametersString appendFormat:@"\n - %@: %@", key, self.parameters[key]];
NSString *const indentation = [@"" stringByPaddingToLength:(key.length + 5) withString:@" " startingAtIndex:0];
NSString *const indentedValue = [self.parameters[key] stringByReplacingOccurrencesOfString:@"\n"
withString:[NSString stringWithFormat:@"\n%@", indentation]];
[parametersString appendFormat:@"\n - %@: %@", key, indentedValue];
}

return [NSString stringWithFormat:@"[%@] %@%@", dateString, self.text, parametersString];
Expand Down
25 changes: 25 additions & 0 deletions Sources/CoreAardvarkTests/ARKDefaultLogFormatterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,31 @@ - (void)test_formattedLogMessage_parameters;
[self waitForExpectationsWithTimeout:5.0 handler:nil];
}

- (void)test_formattedLogMessage_multilineParameter;
{
ARKLogWithParameters(@{@"Some Key": @"This is a\nparameter value that\nspans multiple lines"}, @"Test message");

XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.logStore retrieveAllLogMessagesWithCompletionHandler:^(NSArray *logMessages) {
XCTAssertEqual(logMessages.count, 1);

ARKLogMessage *const firstLogMessage = logMessages.firstObject;
NSString *const formattedSingleLog = [self.logFormatter formattedLogMessage:firstLogMessage];
NSArray<NSString *> *const splitLog = [formattedSingleLog componentsSeparatedByString:@"\n"];
NSString *const formattedParameters = [[splitLog subarrayWithRange:NSMakeRange(1, splitLog.count - 1)] componentsJoinedByString:@"\n"];

NSString *const expectedFormattedParameters = @" - Some Key: This is a\n"
" parameter value that\n"
" spans multiple lines";

XCTAssert([formattedParameters isEqualToString:expectedFormattedParameters]);

[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:5.0 handler:nil];
}

#pragma mark - Performance Tests

- (void)test_formattedLogMessage_performance;
Expand Down

0 comments on commit 79deb1f

Please sign in to comment.