Skip to content

Commit a019f47

Browse files
committed
finish report logs
1 parent 8c01746 commit a019f47

File tree

1 file changed

+73
-11
lines changed

1 file changed

+73
-11
lines changed

src/qiniu.js

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,36 @@
766766
return key;
767767
};
768768

769+
var getDomainFromUrl = function (url) {
770+
if (url && url.match) {
771+
var groups = url.match(/^https?:\/\/([^:^/]*)/);
772+
return groups ? groups[1] : "";
773+
}
774+
return "";
775+
}
776+
777+
var getPortFromUrl = function (url) {
778+
if (url && url.match) {
779+
var groups = url.match(/(^https?)/)
780+
if (!groups) {
781+
return "";
782+
}
783+
var type = groups[1];
784+
groups = url.match(/^https?:\/\/([^:^/]*):(\d*)/);
785+
if (groups) {
786+
return groups[2];
787+
} else if (type == "http") {
788+
return "80";
789+
} else {
790+
return "443";
791+
}
792+
}
793+
return "";
794+
}
795+
769796
function StatisticsLogger() {
770797
// api to collect upload logs
771-
var qiniuCollectUploadLogUrl = "https://uplog.qbox.me/log/2";
798+
var qiniuCollectUploadLogUrl = "https://uplog.qbox.me/log/3";
772799

773800
/**
774801
* { log: string, status: number }[] status: 0 待处理, 1 正在发送, 2 发送完毕
@@ -785,11 +812,16 @@
785812
*
786813
* @param {number} code status code
787814
* @param {string} req_id request id
815+
* @param {string} host
816+
* @param {string} remote_ip
817+
* @param {string} port
818+
* @param {string} duration
819+
* @param {string} up_time
820+
* @param {number} bytes_sent uploaded size (bytes)
821+
* @param {string} up_type js sdk runtime: html5, html4, flash
788822
* @param {number} file_size file total size (bytes)
789-
* @param {number} sent_size uploaded size (bytes)
790-
* @param {string} sdk_runtime js sdk runtime: html5, html4, flash
791823
*/
792-
this.log = function (code, req_id, file_size, sent_size, sdk_runtime) {
824+
this.log = function (code, req_id, host, remote_ip, port, duration, up_time, bytes_sent, up_type, file_size) {
793825
var log = Array.prototype.join.call(arguments, ',');
794826
queue.push({
795827
log: log,
@@ -1319,11 +1351,19 @@
13191351
// add send log for upload error
13201352
var matchedGroups = (err && err.responseHeaders && err.responseHeaders.match) ? err.responseHeaders.match(/(X-Reqid\:\ )([^,]*)/) : []
13211353
var req_id = matchedGroups[2]
1354+
var errcode = plupload.HTTP_ERROR ? err.status : err.code, req_id
13221355
statisticsLogger.log(
1323-
err.code == plupload.HTTP_ERROR ? err.status : err.code, req_id,
1324-
err.file.size,
1356+
errcode == 0 ? ExtraErrors.NetworkError: errcode,
1357+
req_id,
1358+
getDomainFromUrl(up.settings.url),
1359+
undefined,
1360+
getPortFromUrl(up.settings.url),
1361+
undefined,
1362+
file.lastModifiedDate.getTime(),
13251363
err.file.size * (err.file.percent / 100),
1326-
up.runtime);
1364+
"jssdk-" + up.runtime,
1365+
file.size
1366+
)
13271367
};
13281368
})(_Error_Handler));
13291369

@@ -1462,9 +1502,20 @@
14621502
last_step(up, file, info);
14631503
}
14641504

1465-
// TODO status code ? send log for upload complete
1505+
// send statistics log
14661506
var req_id = info.responseHeaders.match(/(X-Reqid\:\ )([^,]*)/)[2]
1467-
statisticsLogger.log(info.status, req_id, file.size, file.size, up.runtime);
1507+
statisticsLogger.log(
1508+
info.status,
1509+
req_id,
1510+
getDomainFromUrl(up.settings.url),
1511+
undefined,
1512+
getPortFromUrl(up.settings.url),
1513+
undefined,
1514+
file.lastModifiedDate.getTime(),
1515+
file.size,
1516+
"jssdk-" + up.runtime,
1517+
file.size
1518+
)
14681519
};
14691520
})(_FileUploaded_Handler));
14701521

@@ -1474,9 +1525,20 @@
14741525
// intercept the cancel of upload
14751526
// used to send statistics log to server
14761527
uploader.bind('FilesRemoved', function (up, files) {
1477-
// TODO status code ? add cancel log
1528+
// add cancel log
14781529
for (var i = 0; i < files.length; i++) {
1479-
statisticsLogger.log(ExtraErrors.Cancelled, undefined, files[i].size, files[i].size * files[i].percent / 100, up.runtime);
1530+
statisticsLogger.log(
1531+
ExtraErrors.Cancelled,
1532+
undefined,
1533+
getDomainFromUrl(up.settings.url),
1534+
undefined,
1535+
getPortFromUrl(up.settings.url),
1536+
undefined,
1537+
files[i].lastModifiedDate.getTime(),
1538+
files[i].size,
1539+
"jssdk-" + up.runtime,
1540+
files[i].size
1541+
);
14801542
}
14811543
})
14821544

0 commit comments

Comments
 (0)