Add endpoint to obtain logs
It goes through a WebSocket; the secret is sent, and if valid, the logs are sent back.
This commit is contained in:
20
lib/log.js
20
lib/log.js
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const listeners = [];
|
||||
|
||||
// Zero-pad a number in a string.
|
||||
// eg. 4 becomes 04 but 17 stays 17.
|
||||
function pad(string) {
|
||||
@@ -19,9 +21,23 @@ function date() {
|
||||
}
|
||||
|
||||
module.exports = function log(...msg) {
|
||||
console.log(date(), ...msg);
|
||||
const d = date();
|
||||
listeners.forEach(f => f(d, ...msg))
|
||||
console.log(d, ...msg);
|
||||
};
|
||||
|
||||
module.exports.error = function error(...msg) {
|
||||
console.error(date(), ...msg);
|
||||
const d = date();
|
||||
listeners.forEach(f => f(d, ...msg))
|
||||
console.error(d, ...msg);
|
||||
};
|
||||
|
||||
module.exports.addListener = function addListener(func) {
|
||||
listeners.push(func);
|
||||
};
|
||||
|
||||
module.exports.removeListener = function removeListener(func) {
|
||||
const index = listeners.indexOf(func);
|
||||
if (index < 0) { return; }
|
||||
listeners.splice(index, 1);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user