logging
This commit is contained in:
parent
2e8e8f35e7
commit
f0c0d0223b
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,5 @@
|
|||||||
# Logs
|
# Logs
|
||||||
logs
|
/logs/*.log
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
@ -86,3 +86,5 @@ isJson = (str) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
vorpal.delimiter('auth@rxbn$').show();
|
vorpal.delimiter('auth@rxbn$').show();
|
||||||
|
|
||||||
|
module.exports = vorpal;
|
||||||
|
84
bin/logs/module.js
Normal file
84
bin/logs/module.js
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the authRxbn eco-system.
|
||||||
|
*
|
||||||
|
* (c) Ruben Meyer <contact@rxbn.de>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
var methods = {};
|
||||||
|
let fs = require('fs');
|
||||||
|
let util = require('util');
|
||||||
|
|
||||||
|
// LOG | INFO
|
||||||
|
methods.log = (...data) => {
|
||||||
|
global['modules'].cli.log.apply(global['modules'].cli, data);
|
||||||
|
|
||||||
|
if(data.length == 1) data = data[0];
|
||||||
|
newLine(" [LOG]", data);
|
||||||
|
};
|
||||||
|
methods.info = methods.log;
|
||||||
|
|
||||||
|
// WARNING
|
||||||
|
methods.warn = (...data) => {
|
||||||
|
global['modules'].cli.log.apply(global['modules'].cli, data);
|
||||||
|
|
||||||
|
if(data.length == 1) data = data[0];
|
||||||
|
newLine(" [WARN]", data);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ERROR
|
||||||
|
methods.error = (...data) => {
|
||||||
|
global['modules'].cli.log.apply(global['modules'].cli, data);
|
||||||
|
|
||||||
|
if(data.length == 1) data = data[0];
|
||||||
|
newLine("[ERROR]", data);
|
||||||
|
};
|
||||||
|
methods.err = methods.error;
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
methods.debug = (...data) => {
|
||||||
|
if(global['gds'].debug) {
|
||||||
|
global['modules'].cli.log.apply(global['modules'].cli, data);
|
||||||
|
|
||||||
|
if(data.length == 1) data = data[0];
|
||||||
|
newLine("[DEBUG]", data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// save new line to file
|
||||||
|
newLine = (prefix, obj) => {
|
||||||
|
let date = new Date(); // current date
|
||||||
|
let filename = new Date().toISOString().substr(0, 10) + ".log"; // filename
|
||||||
|
let path = global['__dirname'] + "/logs/"+ filename; // filepath
|
||||||
|
let fs_options = { // fs options for encoding, file mode and file flag
|
||||||
|
encoding: "utf8",
|
||||||
|
flag: "a+"
|
||||||
|
};
|
||||||
|
let date_string =
|
||||||
|
("0" + date.getUTCHours()).slice(-2) + ":" +
|
||||||
|
("0" + date.getUTCMinutes()).slice(-2) + ":" +
|
||||||
|
("0" + date.getUTCSeconds()).slice(-2);
|
||||||
|
|
||||||
|
|
||||||
|
// type matching
|
||||||
|
if(
|
||||||
|
typeof obj == "string" ||
|
||||||
|
typeof obj == "number" ||
|
||||||
|
typeof obj == "boolean"
|
||||||
|
) fs.appendFileSync(path, prefix + " " + date_string + " | " + obj + "\n", fs_options);
|
||||||
|
else
|
||||||
|
if(typeof obj == "object") {
|
||||||
|
let lines = JSON.stringify(obj, null, '\t'); // prettyprint obj as JSON
|
||||||
|
lines.split(/\r?\n/).forEach((line) => { // for each linebreak (\r | \n)
|
||||||
|
fs.appendFileSync(path, prefix + " " + date_string + " | " + line + "\n", fs_options);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// do nothing; not supported
|
||||||
|
// typeof obj == "symbol"
|
||||||
|
// typeof obj == "undefined"
|
||||||
|
// typeof obj == "function"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = methods;
|
@ -94,7 +94,7 @@ methods.start = () => {
|
|||||||
|
|
||||||
// start server
|
// start server
|
||||||
app.listen(global['gds'].cfg.web.port, () => {
|
app.listen(global['gds'].cfg.web.port, () => {
|
||||||
console.log("Server is listening on port: "+global['gds'].cfg.web.port);
|
global['modules'].logs.log("Server is listening on port: "+global['gds'].cfg.web.port);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
0
logs/.ignore
Normal file
0
logs/.ignore
Normal file
Loading…
x
Reference in New Issue
Block a user