Skip to content

Commit

Permalink
keep RadarLog.h
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiCheng-Lu committed Sep 24, 2024
1 parent 8db6df0 commit 84b4711
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIWindowSceneDelegate, UN
Radar.setMetadata([ "foo": "bar" ])
Radar.setDelegate(self)
Radar.setVerifiedDelegate(self)



return true
}

Expand Down
8 changes: 8 additions & 0 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
F65AF72C2C10B242002BA009 /* get_config_response.json in Resources */ = {isa = PBXBuildFile; fileRef = F65AF72B2C10B242002BA009 /* get_config_response.json */; };
F662C8B42CA1BF86001B24EC /* RadarLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = F662C8B32CA1BF86001B24EC /* RadarLog.swift */; };
F662C8B62CA1C96C001B24EC /* RadarUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = F662C8B52CA1C96C001B24EC /* RadarUtils.swift */; };
F662C9012CA3144B001B24EC /* RadarUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = F662C9002CA3144B001B24EC /* RadarUtils.h */; };
F662C9022CA3144B001B24EC /* RadarLog.h in Headers */ = {isa = PBXBuildFile; fileRef = F662C8FF2CA3144B001B24EC /* RadarLog.h */; };
F667F8272BFBF3C8001F2F67 /* RadarSdkConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */; };
F667F8292BFBF3D1001F2F67 /* RadarSdkConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */; };
F6F959802C3D7D9900BC30FE /* RadarTimeZone.h in Headers */ = {isa = PBXBuildFile; fileRef = F6F9597F2C3D7D9900BC30FE /* RadarTimeZone.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -340,6 +342,8 @@
F65AF72B2C10B242002BA009 /* get_config_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = get_config_response.json; sourceTree = "<group>"; };
F662C8B32CA1BF86001B24EC /* RadarLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadarLog.swift; sourceTree = "<group>"; };
F662C8B52CA1C96C001B24EC /* RadarUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadarUtils.swift; sourceTree = "<group>"; };
F662C8FF2CA3144B001B24EC /* RadarLog.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarLog.h; sourceTree = "<group>"; };
F662C9002CA3144B001B24EC /* RadarUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarUtils.h; sourceTree = "<group>"; };
F667F8262BFBF3C8001F2F67 /* RadarSdkConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarSdkConfiguration.m; sourceTree = "<group>"; };
F667F8282BFBF3D1001F2F67 /* RadarSdkConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RadarSdkConfiguration.h; sourceTree = "<group>"; };
F6F9597F2C3D7D9900BC30FE /* RadarTimeZone.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarTimeZone.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -489,6 +493,7 @@
DD4C104925D87E3E009C2E36 /* RadarDelegateHolder.m */,
DD236CF723088F8400EB88F9 /* RadarLocationManager.h */,
DD236CF823088F8400EB88F9 /* RadarLocationManager.m */,
F662C8FF2CA3144B001B24EC /* RadarLog.h */,
F662C8B32CA1BF86001B24EC /* RadarLog.swift */,
96A5A11627ADA02E007B960B /* RadarLogBuffer.h */,
DD236D66230A0D6700EB88F9 /* RadarLogger.h */,
Expand All @@ -512,6 +517,7 @@
DD236D0F2309B3FE00EB88F9 /* RadarState.m */,
DD236CEB2308821600EB88F9 /* RadarTrackingOptions.m */,
DD8CCDF7246872360011690D /* RadarTripOptions.m */,
F662C9002CA3144B001B24EC /* RadarUtils.h */,
F662C8B52CA1C96C001B24EC /* RadarUtils.swift */,
82F7FAEC2A65FE030055AA4B /* RadarVerificationManager.h */,
82F7FAED2A65FE030055AA4B /* RadarVerificationManager.m */,
Expand Down Expand Up @@ -622,6 +628,8 @@
96A5A0D627AD9F41007B960B /* RadarRouteMatrix+Internal.h in Headers */,
96A5A0FA27AD9F7F007B960B /* RadarRouteMatrix.h in Headers */,
96A5A0CC27AD9F41007B960B /* RadarUser+Internal.h in Headers */,
F662C9012CA3144B001B24EC /* RadarUtils.h in Headers */,
F662C9022CA3144B001B24EC /* RadarLog.h in Headers */,
96A5A10327AD9F7F007B960B /* RadarGeofence.h in Headers */,
0107AA222622005B008AB52F /* RadarState.h in Headers */,
96A5A11A27ADA02F007B960B /* RadarLogBuffer.h in Headers */,
Expand Down
1 change: 1 addition & 0 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#import "RadarNotificationHelper.h"

#import "RadarSDK/RadarSDK-Swift.h"
#import "RadarLog.h"

@interface Radar ()

Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/RadarAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#import "RadarVerifiedLocationToken+Internal.h"
#import <os/log.h>

#import "RadarSDK/RadarSDK-Swift.h"
#import "RadarLog.h"

@implementation RadarAPIClient

Expand Down
59 changes: 59 additions & 0 deletions RadarSDK/RadarLog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// RadarLog.h
// RadarSDK
//
// Copyright © 2021 Radar Labs, Inc. All rights reserved.
//

#import "Radar.h"

/**
Represents a debug log.
*/
@interface RadarLog : NSObject <NSCoding>

/**
The levels for debug logs.
*/
@property (assign, nonatomic, readonly) RadarLogLevel level;

/**
The log message.
*/
@property (nonnull, copy, nonatomic, readonly) NSString *message;

/**
The log type.
*/
@property (assign, nonatomic, readonly) RadarLogType type;

/**
The datetime when the log occurred on the device.
*/
@property (nonnull, copy, nonatomic, readonly) NSDate *createdAt;

- (instancetype _Nullable)initWithLevel:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *_Nullable)message;

- (NSDictionary *_Nonnull)dictionaryValue;

+ (NSArray<NSDictionary *> *_Nullable)arrayForLogs:(NSArray<RadarLog *> *_Nullable)logs NS_SWIFT_NAME(arrayForLogs(_:));

/**
Returns a display string for a log level.
@param level A log level
@return A display string for the log level.
*/
+ (NSString *_Nonnull)stringForLogLevel:(RadarLogLevel)level NS_SWIFT_NAME(stringForLogLevel(_:));

/**
Return the log level for a specific display string
@param string A display string for the log level
@return A log level.
*/
+ (RadarLogLevel) levelFromString:(NSString *_Nonnull) string;

@end
30 changes: 27 additions & 3 deletions RadarSDK/RadarLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@
import Foundation


@objc public class RadarLog: NSObject {
@objc(RadarLog)
class RadarLog: NSObject, NSCoding {
public func encode(with coder: NSCoder) {
coder.encode(level, forKey: "level")
coder.encode(message, forKey: "message")
coder.encode(type.rawValue, forKey: "type")
coder.encode(createdAt, forKey: "createdAt")
}

public required convenience init?(coder: NSCoder) {
let level = coder.decodeObject(forKey: "level") as! RadarLogLevel
let type = RadarLogType(rawValue: coder.decodeObject(forKey: "type") as! Int)!
let message = coder.decodeObject(forKey: "message") as! NSString
let createdAt = coder.decodeObject(forKey: "createdAt") as! NSDate

self.init(level: level, type: type, message: message)
}

/**
The levels for debug logs.
*/
Expand All @@ -30,11 +47,11 @@ import Foundation
*/
@objc public let createdAt: NSDate;

@objc public init(level: RadarLogLevel, type: RadarLogType, message: NSString, createdAt: NSDate) {
@objc public init(level: RadarLogLevel, type: RadarLogType, message: NSString) {
self.level = level
self.message = message
self.type = type
self.createdAt = createdAt
self.createdAt = NSDate()
}

@objc public func dictionaryValue() -> Dictionary<String, Any> {
Expand Down Expand Up @@ -135,5 +152,12 @@ import Foundation
return RadarLogLevel.info;
}
}
//
// @objc public func encode(withCoder coder: NSCoder){
// coder.encode(level.rawValue, forKey: "level")
// coder.encode(message, forKey: "message")
// coder.encode(type.rawValue, forKey: "type")
// coder.encode(createdAt, forKey: "createdAt")
// }

}
8 changes: 4 additions & 4 deletions RadarSDK/RadarLogBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

#import "RadarLogBuffer.h"
#import "RadarSDK/RadarSDK-Swift.h"
#import "RadarLog.h"
#import "RadarFileStorage.h"
#import "RadarSettings.h"

Expand Down Expand Up @@ -60,7 +60,7 @@ - (void)write:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *)m
}

- (void)write:(RadarLogLevel)level type:(RadarLogType)type message:(NSString *)message forcePersist:(BOOL)forcePersist {
RadarLog *radarLog = [[RadarLog alloc] initWithLevel:level type:type message:message createdAt:[NSDate new]];
RadarLog *radarLog = [[RadarLog alloc] initWithLevel:level type:type message:message];

// bypass sync lock here to ensure that other writes or persisting logs don't block the current thread as the app is terminating
if (forcePersist && (_persistentLogFeatureFlag || [[NSProcessInfo processInfo] environment][@"XCTestConfigurationFilePath"])) {
Expand Down Expand Up @@ -159,14 +159,14 @@ - (void)purgeOldestLogs {
dirSize = [[self getLogFilesInTimeOrder] count];
if (!printedPurgedLogs) {
printedPurgedLogs = YES;
RadarLog *purgeLog = [[RadarLog alloc] initWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:kPurgedLogLine createdAt:[NSDate new]];
RadarLog *purgeLog = [[RadarLog alloc] initWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:kPurgedLogLine];
[self writeToFileStorage:@[purgeLog]];
}
}
} else {
// drop the oldest N logs from the buffer
[logBuffer removeObjectsInRange:NSMakeRange(0, PURGE_AMOUNT)];
RadarLog *purgeLog = [[RadarLog alloc] initWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:kPurgedLogLine createdAt:[NSDate new]];
RadarLog *purgeLog = [[RadarLog alloc] initWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:kPurgedLogLine];
[logBuffer insertObject:purgeLog atIndex:0];
}
}
Expand Down
1 change: 1 addition & 0 deletions RadarSDK/RadarReplayBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ - (void)writeNewReplayToBuffer:(NSMutableDictionary *)replayParams {
return flushableReplays;
}

// function name?
- (void)flushReplaysWithCompletionHandler:(NSDictionary *_Nullable)replayParams
completionHandler:(RadarFlushReplaysCompletionHandler _Nullable)completionHandler {
if (isFlushing) {
Expand Down
2 changes: 1 addition & 1 deletion RadarSDK/RadarSdkConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#import "RadarAPIClient.h"
#import "RadarSettings.h"
#import "RadarSDK/RadarSDK-Swift.h"
#import "RadarLog.h"

@implementation RadarSdkConfiguration

Expand Down
39 changes: 39 additions & 0 deletions RadarSDK/RadarUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// RadarUtils.h
// RadarSDK
//
// Copyright © 2019 Radar Labs, Inc. All rights reserved.
//

#import <CoreLocation/CLLocation.h>
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface RadarUtils : NSObject

@property (class, nonatomic, assign, readonly) NSDateFormatter *isoDateFormatter;

+ (NSString *)deviceModel;
+ (NSString *)deviceOS;
+ (NSString *)country;
+ (NSNumber *)timeZoneOffset;
+ (NSString *)sdkVersion;
+ (NSString *)deviceId;
+ (NSString *)deviceType;
+ (NSString *)deviceMake;
+ (BOOL)isSimulator;
+ (BOOL)locationBackgroundMode;
+ (NSString *)locationAuthorization;
+ (NSString *)locationAccuracyAuthorization;
+ (BOOL)foreground;
+ (NSTimeInterval)backgroundTimeRemaining;
+ (CLLocation *)locationForDictionary:(NSDictionary *_Nonnull)dict;
+ (NSDictionary *)dictionaryForLocation:(CLLocation *)location;
+ (NSString *)dictionaryToJson:(NSDictionary *)dict;
+ (NSDictionary<NSString *, NSString *> *)extractGeofenceIdAndTimestampFromIdentifier:(NSString *)identifier;
+ (void)runOnMainThread:(dispatch_block_t)block;

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion RadarSDKTests/RadarSDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ - (void)test_Radar_getContext_errorLocation {

[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:60
handler:^(NSError *_Nullable error) {
if (error) {
Expand Down

0 comments on commit 84b4711

Please sign in to comment.