-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
30 lines (27 loc) · 875 Bytes
/
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
const moment = require('moment-timezone');
moment().tz("America/Los_Angeles").format();
var date = moment().format('YYYY-MM-DD');
var time = moment().format('H:mm');
var fs = require('fs');
var log = {
init: function () {
if(!fs.existsSync(__dirname + '/logs/' + date + '-events.log')){
fs.writeFile(__dirname + '/logs/' + date + '-events.log', '', function(err) {
if(err) {
console.log(err);
}
});
}
},
event: function (data, err) {
var stream = fs.createWriteStream(__dirname + '/logs/' + date + '-events.log', {flags: 'a'});
var error = '';
if(err !== undefined){
error = err;
}
stream.write(time + " " + data + error + "\n");
stream.end();
console.log(data, error);
}
};
module.exports = log;