Skip to content

Commit 13a83d9

Browse files
committed
1.QNResponse add xClientId
2.fix uplog json format 3.change uplog up_time unit from ms to s
1 parent bf4336f commit 13a83d9

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

QiniuSDK/Http/QNResponseInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ extern const int kQNFileError;
5555
*/
5656
@property (nonatomic, copy, readonly) NSString *reqId;
5757

58+
/**
59+
* 七牛日志上报返回的X_Log_Client_Id
60+
*/
61+
@property (nonatomic, copy, readonly) NSString *xClientId;
62+
5863
/**
5964
* 七牛服务器内部跟踪记录
6065
*/

QiniuSDK/Http/QNResponseInfo.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "QNHttpResponseInfo.h"
1111
#import "QNUserAgent.h"
1212
#import "QNVersion.h"
13+
#import "QNUploadInfoReporter.h"
1314

1415
const int kQNZeroDataSize = -6;
1516
const int kQNInvalidToken = -5;
@@ -127,6 +128,7 @@ - (instancetype)initWithStatus:(int)status
127128
_duration = duration;
128129
_id = [QNUserAgent sharedInstance].id;
129130
_timeStamp = [[NSDate date] timeIntervalSince1970];
131+
_xClientId = Reporter.X_Log_Client_Id;
130132
}
131133
return self;
132134
}
@@ -158,12 +160,13 @@ - (instancetype)initWithStatusCode:(int)statusCode
158160
_duration = duration;
159161
_id = [QNUserAgent sharedInstance].id;
160162
_timeStamp = [[NSDate date] timeIntervalSince1970];
163+
_xClientId = Reporter.X_Log_Client_Id;
161164
}
162165
return self;
163166
}
164167

165168
- (NSString *)description {
166-
return [NSString stringWithFormat:@"<%@= id: %@, ver: %@, status: %d, requestId: %@, xlog: %@, xvia: %@, host: %@ duration: %.3f s time: %llu error: %@>", NSStringFromClass([self class]), _id, kQiniuVersion, _statusCode, _reqId, _xlog, _xvia, _host, _duration, _timeStamp, _error];
169+
return [NSString stringWithFormat:@"<%@= id: %@, ver: %@, status: %d, requestId: %@, xClientId: %@, xlog: %@, xvia: %@, host: %@ duration: %.3f s time: %llu error: %@>", NSStringFromClass([self class]), _id, kQiniuVersion, _statusCode, _reqId, _xClientId, _xlog, _xvia, _host, _duration, _timeStamp, _error];
167170
}
168171

169172
- (BOOL)isCancelled {

QiniuSDK/Storage/QNUploadInfoReporter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124

125125
@interface QNUploadInfoReporter : NSObject
126126

127+
@property (nonatomic, copy, readonly) NSString *X_Log_Client_Id;
128+
127129
- (id)init __attribute__((unavailable("Use sharedInstance: instead.")));
128130
+ (instancetype)sharedInstance;
129131

QiniuSDK/Storage/QNUploadInfoReporter.m

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ - (instancetype)init
2929
{
3030
self = [super init];
3131
if (self) {
32-
self.up_time = [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970] * 1000;
32+
self.up_time = [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970];
3333
}
3434
return self;
3535
}
3636
- (NSString *)toJson {
37-
NSMutableDictionary *requestItemDic = [NSMutableDictionary dictionary];
37+
NSMutableDictionary *itemDic = [NSMutableDictionary dictionary];
3838

3939
// self class property
4040
unsigned int selfPropertyCount = 0;
@@ -52,12 +52,12 @@ - (NSString *)toJson {
5252
if (0 == strcmp(value, "@\"NSString\"")) {
5353
NSString *key = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
5454
NSString *ivarValue = [self valueForKey:key];
55-
if (ivarValue) [requestItemDic setValue:ivarValue forKey:key];
55+
if (ivarValue) [itemDic setValue:ivarValue forKey:key];
5656
} else {
5757
// 默认其他属性的基本类型是int
5858
NSString *key = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
5959
NSNumber *ivarValue = [self valueForKey:key];
60-
if (ivarValue && ![ivarValue isEqualToNumber:@(QN_IntNotSet)]) [requestItemDic setValue:ivarValue forKey:key];
60+
if (ivarValue && ![ivarValue isEqualToNumber:@(QN_IntNotSet)]) [itemDic setValue:ivarValue forKey:key];
6161
}
6262
}
6363
}
@@ -81,12 +81,12 @@ - (NSString *)toJson {
8181
if (0 == strcmp(value, "@\"NSString\"")) {
8282
NSString *key = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
8383
NSString *ivarValue = [self valueForKey:key];
84-
if (ivarValue) [requestItemDic setValue:ivarValue forKey:key];
84+
if (ivarValue) [itemDic setValue:ivarValue forKey:key];
8585
} else {
8686
// 默认其他属性的基本类型是int
8787
NSString *key = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
8888
NSNumber *ivarValue = [self valueForKey:key];
89-
if (ivarValue) [requestItemDic setValue:ivarValue forKey:key];
89+
if (ivarValue) [itemDic setValue:ivarValue forKey:key];
9090
}
9191
}
9292
}
@@ -95,10 +95,13 @@ - (NSString *)toJson {
9595
free(superProperties);
9696

9797
NSError *error;
98-
NSData *requestItemData = [NSJSONSerialization dataWithJSONObject:requestItemDic options:NSJSONWritingPrettyPrinted error:&error];
98+
NSData *itemData = [NSJSONSerialization dataWithJSONObject:itemDic options:NSJSONWritingPrettyPrinted error:&error];
9999
if (error) return nil;
100-
NSString *requestItemJson = [[NSString alloc] initWithData:requestItemData encoding:NSUTF8StringEncoding];
101-
return requestItemJson;
100+
NSString *itemJson = [[NSString alloc] initWithData:itemData encoding:NSUTF8StringEncoding];
101+
NSMutableString *formatJsonString = [NSMutableString stringWithString:itemJson];
102+
[formatJsonString replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:NSMakeRange(0, formatJsonString.length)];
103+
[formatJsonString replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, formatJsonString.length)];
104+
return formatJsonString;
102105
}
103106
@end
104107

@@ -398,7 +401,7 @@ @interface QNUploadInfoReporter ()
398401
@property (nonatomic, strong) NSString *recorderFilePath;
399402
@property (nonatomic, strong) dispatch_queue_t recordQueue;
400403
@property (nonatomic, strong) dispatch_semaphore_t semaphore;
401-
@property (nonatomic, copy) NSString *X_Log_Client_Id;
404+
@property (nonatomic, copy, readwrite) NSString *X_Log_Client_Id;
402405

403406
@end
404407

0 commit comments

Comments
 (0)