Skip to content

Commit f2ee370

Browse files
committed
add debug logs
1 parent 3c9c7d3 commit f2ee370

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

api/utils/countlyFs.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ countlyFs.gridfs = {};
121121
* });
122122
*/
123123
ob.getId = function(category, filename, callback) {
124+
log.d("getId", category, filename);
124125
db.collection(category + ".files").findOne({ filename: filename }, {_id: 1}, function(err, res) {
125126
if (callback) {
126127
callback(err, (res && res._id) ? res._id : false);
@@ -149,6 +150,7 @@ countlyFs.gridfs = {};
149150
if (!options) {
150151
options = {};
151152
}
153+
log.d("exists", category, dest, options);
152154
var query = {};
153155
if (options.id) {
154156
query._id = options.id;
@@ -189,7 +191,7 @@ countlyFs.gridfs = {};
189191
if (!options) {
190192
options = {};
191193
}
192-
194+
log.d("saveFile", category, dest, source, options);
193195
var filename = dest.split(path.sep).pop();
194196
beforeSave(category, filename, options, callback, function() {
195197
save(category, filename, fs.createReadStream(source), options, callback);
@@ -223,6 +225,7 @@ countlyFs.gridfs = {};
223225
if (!options) {
224226
options = {};
225227
}
228+
log.d("saveData", category, dest, typeof data, options);
226229
beforeSave(category, filename, options, callback, function() {
227230
var readStream = new Readable;
228231
readStream.push(data);
@@ -258,6 +261,7 @@ countlyFs.gridfs = {};
258261
if (!options) {
259262
options = {};
260263
}
264+
log.d("saveStream", category, dest, typeof readStream, options);
261265
beforeSave(category, filename, options, callback, function() {
262266
save(category, filename, readStream, options, callback);
263267
});
@@ -286,7 +290,7 @@ countlyFs.gridfs = {};
286290
if (!options) {
287291
options = {};
288292
}
289-
293+
log.d("rename", category, dest, source, options);
290294
if (options.id) {
291295
let bucket = new GridFSBucket(db, { bucketName: category });
292296
let errHandle = null;
@@ -352,7 +356,7 @@ countlyFs.gridfs = {};
352356
if (!options) {
353357
options = {};
354358
}
355-
359+
log.d("deleteFile", category, dest, options);
356360
if (options.id) {
357361
ob.deleteFileById(category, options.id, callback);
358362
}
@@ -388,6 +392,7 @@ countlyFs.gridfs = {};
388392
* });
389393
*/
390394
ob.deleteAll = async function(category, dest, callback) {
395+
log.d("deleteAll", category, dest);
391396
var bucket = new GridFSBucket(db, { bucketName: category });
392397
let errHandle = null;
393398
try {
@@ -423,7 +428,7 @@ countlyFs.gridfs = {};
423428
if (!options) {
424429
options = {};
425430
}
426-
431+
log.d("getStream", category, dest, options);
427432
if (callback) {
428433
if (options.id) {
429434
ob.getStreamById(category, options.id, callback);
@@ -456,7 +461,7 @@ countlyFs.gridfs = {};
456461
if (!options) {
457462
options = {};
458463
}
459-
464+
log.d("getData", category, dest, options);
460465
if (options.id) {
461466
ob.getDataById(category, options.id, callback);
462467
}
@@ -502,7 +507,7 @@ countlyFs.gridfs = {};
502507
if (!options) {
503508
options = {};
504509
}
505-
510+
log.d("getSize", category, dest, options);
506511
var query = {};
507512
if (options.id) {
508513
query._id = options.id;
@@ -537,7 +542,7 @@ countlyFs.gridfs = {};
537542
if (!options) {
538543
options = {};
539544
}
540-
545+
log.d("getStats", category, dest, options);
541546
var query = {};
542547
if (options.id) {
543548
query._id = options.id;
@@ -574,6 +579,7 @@ countlyFs.gridfs = {};
574579
* });
575580
*/
576581
ob.getDataById = function(category, id, callback) {
582+
log.d("getDataById", category, id);
577583
var bucket = new GridFSBucket(db, { bucketName: category });
578584
var downloadStream = bucket.openDownloadStream(id);
579585
downloadStream.on('error', function(error) {
@@ -605,6 +611,7 @@ countlyFs.gridfs = {};
605611
* });
606612
*/
607613
ob.getStreamById = function(category, id, callback) {
614+
log.d("getStreamById", category, id);
608615
if (callback) {
609616
var bucket = new GridFSBucket(db, { bucketName: category });
610617
callback(null, bucket.openDownloadStream(id));
@@ -622,6 +629,7 @@ countlyFs.gridfs = {};
622629
* });
623630
*/
624631
ob.deleteFileById = async function(category, id, callback) {
632+
log.d("deleteFileById", category, id);
625633
var bucket = new GridFSBucket(db, { bucketName: category });
626634
let errHandle = null;
627635
try {
@@ -646,6 +654,7 @@ countlyFs.gridfs = {};
646654
* });
647655
*/
648656
ob.clearFile = function(category, filename, callback) {
657+
log.d("clearFile", category, filename);
649658
db.collection(category + ".files").deleteMany({ filename: filename }, function(err1, res1) {
650659
log.d("deleting files", category, { filename: filename }, err1, res1 && res1.result);
651660
db.collection(category + ".chunks").deleteMany({ files_id: filename }, function(err2, res2) {
@@ -662,6 +671,7 @@ countlyFs.gridfs = {};
662671
* @param {function} callback - function called when files found or query errored, providing error object as first param and a list of filename, creation date and size as secondas second
663672
*/
664673
ob.listFiles = function(category, callback) {
674+
log.d("listFiles", category);
665675
const bucket = new GridFSBucket(db, { bucketName: category });
666676
bucket.find().toArray()
667677
.then((records) => callback(

0 commit comments

Comments
 (0)