-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogger.js
49 lines (45 loc) · 1.53 KB
/
logger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Created by tal on 10/4/16.
*/
const fs = require('fs');
// const zlib = require('zlib');
const stream = require('stream');
var gzip = zlib.createGzip();
module.exports = (filePath) => {
var stream = fs.createWriteStream(filePath, {flags: "a", defaultEncoding: "utf8"});
this.logJSON = (input) => {
var flatInput = JSON.stringify(input); // This could potentially be a very expensive operation
// zlib.gzip(flatInput, (err, buffer) => {
// if (!err) {
stream.write(flatInput, (err, res) => {
if (err) {
stream.write(flatInput, () => {}); // No error handling for file write. Just retrying
// TODO: Fix line above later, seriously
}
});
console.log(buffer.toString('base64'));
// } else {
// // No error handling for gzipping, which could be an issue considering the size of the data
// }
// });
};
};
// module.exports = (filePath) => {
// var stream = fs.createWriteStream(filePath, {flags: "a", defaultEncoding: "utf8"});
//
// this.logJSON = (input) => {
// var flatInput = JSON.stringify(input); // This could potentially be a very expensive operation
// zlib.gzip(flatInput, (err, buffer) => {
// if (!err) {
// stream.write(buffer, (err, res) => {
// if (err) {
// stream.write(buffer, () => {}); // No error handling for file write. TODO: Fix later, seriously
// }
// });
// console.log(buffer.toString('base64'));
// } else {
// // No error handling for gzipping, which could be an issue considering the size of the data
// }
// });
// };
// };