-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,601 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
out | ||
out | ||
app.log | ||
config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const fs = require("fs"), path = require("path"); | ||
let p = path.resolve(__dirname, 'config.json') | ||
global.config = {}; | ||
|
||
fs.stat(p, (err, stats) => { | ||
if(!err) { | ||
global.config = require('./config.json'); | ||
} | ||
}) | ||
|
||
global.set = function(key, value) { | ||
global.config[key] = value; | ||
save(); | ||
} | ||
|
||
function save() { | ||
fs.writeFile(p, JSON.stringify(global.config, null, 4), err => {if(err) console.log(err);}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var log = console.log; | ||
var fs = require('fs'); | ||
var log_file = fs.createWriteStream(__dirname + '/app.log', {flags : 'a'}); | ||
|
||
console.log = function () { | ||
let l = [getDate(), ...arguments]; | ||
log_file.write(l.join(" ") + '\n'); | ||
log.apply(console, l); | ||
}; | ||
|
||
function getDate() { | ||
var now = new Date(); | ||
|
||
let day = ('0' + now.getDate()).slice(-2); | ||
let month = ('0' + (now.getMonth() + 1)).slice(-2); | ||
let year = ('0' + now.getFullYear()).slice(-2); | ||
|
||
let hour = ('0' + now.getHours()).slice(-2); | ||
let minute = ('0' + now.getMinutes()).slice(-2); | ||
let seconds = ('0' + now.getSeconds()).slice(-2); | ||
|
||
return `${day}/${month}/${year} ${hour}:${minute}:${seconds}`; | ||
} | ||
|
||
['log', 'warn', 'error'].forEach((methodName) => { | ||
const originalMethod = console[methodName]; | ||
console[methodName] = (...args) => { | ||
let initiator = 'unknown place'; | ||
try { | ||
throw new Error(); | ||
} catch (e) { | ||
if (typeof e.stack === 'string') { | ||
let isFirst = true; | ||
for (const line of e.stack.split('\n')) { | ||
const matches = line.match(/^\s+at\s+(.*)/); | ||
if (matches) { | ||
if (!isFirst) { | ||
initiator = matches[1]; | ||
break; | ||
} | ||
isFirst = false; | ||
} | ||
} | ||
} | ||
} | ||
initiator = initiator.split('\\'); | ||
initiator = '(' + initiator[initiator.length - 1]; | ||
|
||
if (initiator[initiator.length - 1] != ')') { | ||
initiator += ')'; | ||
} | ||
|
||
originalMethod.apply(console, [initiator, ...args]); | ||
}; | ||
}); | ||
|
||
process.on('unhandledRejection', (reason, p) => { | ||
console.error(reason, 'Unhandled Rejection at Promise', p); | ||
}).on('uncaughtException', err => { | ||
console.error(err, 'Uncaught Exception thrown'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.