Skip to content

Commit

Permalink
feat(logging): add timestamp to logs
Browse files Browse the repository at this point in the history
SDK-223

Co-authored-by: davidSchuppa <[email protected]>
  • Loading branch information
LasOri and davidSchuppa committed Feb 4, 2025
1 parent 8d12fc0 commit d123a3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Sources/Core/Log/EMSLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "EMSWrapperChecker.h"
#import "EMSStorageProtocol.h"
#import "EMSMethodNotAllowed.h"
#import "NSDate+EMSCore.h"

@interface EMSLogger ()

Expand Down Expand Up @@ -77,6 +78,7 @@ - (void)log:(id <EMSLogEntryProtocol>)entry
NSMutableDictionary *mutableData = [entry.data mutableCopy];
mutableData[@"level"] = [weakSelf logLevelStringFromLogLevel:level];
mutableData[@"queue"] = currentQueue;
mutableData[@"timestamp"] = [NSString stringWithFormat:@"%@",[[self.timestampProvider provideTimestamp] numberValueInMillis]];
if (![weakSelf.wrapperChecker.wrapper isEqualToString:@"none"]) {
mutableData[@"wrapper"] = weakSelf.wrapperChecker.wrapper;
}
Expand Down
6 changes: 5 additions & 1 deletion Tests/CoreTests/Log/EMSLoggerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "EMSStorageProtocol.h"
#import "EmarsysTestUtils.h"
#import "EMSMethodNotAllowed.h"
#import "NSDate+EMSCore.h"

@interface EMSLoggerTests : XCTestCase

Expand Down Expand Up @@ -217,7 +218,8 @@ - (void)testLogShouldInsertEntryToShardRepository {
OCMVerify([partialMockRepository add:[self shardWithLogLevel:LogLevelError
additionalData:(@{
@"queue": @"testRunnerQueue",
@"wrapper": @"testWrapper"
@"wrapper": @"testWrapper",
@"timestamp": ([NSString stringWithFormat:@"%@",[self.timestamp numberValueInMillis]])
})]]);
}

Expand Down Expand Up @@ -378,6 +380,7 @@ - (void)testShouldLog_whenLogLevelOfLogEntry_isBelowOfLogLevel_butIsAppStartLog
mutableData[@"level"] = @"INFO";
mutableData[@"queue"] = @"testRunnerQueue";
mutableData[@"wrapper"] = @"testWrapper";
mutableData[@"timestamp"] = [NSString stringWithFormat:@"%@",[self.timestamp numberValueInMillis]];

OCMVerify([partialMockRepository add:[[EMSShard alloc] initWithShardId:self.shardId
type:@"app:start"
Expand Down Expand Up @@ -429,6 +432,7 @@ - (void)testLogLevel_useDBSafeDictionaryData {
mutableData[@"level"] = @"INFO";
mutableData[@"queue"] = @"testRunnerQueue";
mutableData[@"wrapper"] = @"testWrapper";
mutableData[@"timestamp"] = [NSString stringWithFormat:@"%@",[self.timestamp numberValueInMillis]];

OCMVerify([partialMockRepository add:[[EMSShard alloc] initWithShardId:self.shardId
type:@"testTopic"
Expand Down

0 comments on commit d123a3c

Please sign in to comment.