Skip to content

Commit 589ed8a

Browse files
authored
Merge pull request #328 from XiaopingSun/QNResponse_add_clientId
fix uplog issue
2 parents bf4336f + e41375c commit 589ed8a

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
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: 10 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,10 @@ - (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:kNilOptions 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+
return itemJson;
102102
}
103103
@end
104104

@@ -398,7 +398,7 @@ @interface QNUploadInfoReporter ()
398398
@property (nonatomic, strong) NSString *recorderFilePath;
399399
@property (nonatomic, strong) dispatch_queue_t recordQueue;
400400
@property (nonatomic, strong) dispatch_semaphore_t semaphore;
401-
@property (nonatomic, copy) NSString *X_Log_Client_Id;
401+
@property (nonatomic, copy, readwrite) NSString *X_Log_Client_Id;
402402

403403
@end
404404

QiniuSDKTests/QNTestConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
// Copyright (c) 2014年 Qiniu. All rights reserved.
77
//
88

9-
static NSString *const g_token = @"bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:bx3SEGbnAAk-AwUEzDP866Ydqio=:eyJzY29wZSI6InNodWFuZ2h1bzEiLCJkZWFkbGluZSI6MTU4OTMzOTc0M30K";
9+
static NSString *const g_token = @"bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW:C2KxWn7I5B3oTUPjtxi9HrrHcvE=:eyJzY29wZSI6InNodWFuZ2h1bzEiLCJkZWFkbGluZSI6MTU4OTk2NjkyNn0K";

0 commit comments

Comments
 (0)