Merged feature/logging-spam-reduction into develop
This commit is contained in:
commit
6cab2ebab8
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
|
- Added basic spam reduction when logging so the same message won't get logged multiple times in a row
|
||||||
- Refactored a bunch of code to improve efficiency
|
- Refactored a bunch of code to improve efficiency
|
||||||
- Updated timer logic to only ever use a single timer, and share it between posting and reconnecting
|
- Updated timer logic to only ever use a single timer, and share it between posting and reconnecting
|
||||||
|
|
||||||
|
|
13
log.js
13
log.js
|
@ -1,26 +1,31 @@
|
||||||
var console = require("console");
|
var console = require("console");
|
||||||
|
|
||||||
|
var latestLog = "";
|
||||||
|
|
||||||
function log(message) {
|
function log(message) {
|
||||||
if (message)
|
if (message && message != latestLog) {
|
||||||
|
latestLog = message; //spam reduction
|
||||||
|
|
||||||
//attach a formatted date string to the beginning of everything we log
|
//attach a formatted date string to the beginning of everything we log
|
||||||
console.log(new Date().toLocaleString() + " " + message);
|
console.log(new Date().toLocaleString() + " " + message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
info: function (message) {
|
info: function (message) {
|
||||||
if (message)
|
if (message)
|
||||||
log("INFO: " + message);
|
log("[INFO] " + message);
|
||||||
},
|
},
|
||||||
event: function (message, sender) {
|
event: function (message, sender) {
|
||||||
//if we received a message, log it - include sender information if it was passed
|
//if we received a message, log it - include sender information if it was passed
|
||||||
if (message) {
|
if (message) {
|
||||||
log("EVENT: " + (sender ? sender + " has sent an event: " : "") + message);
|
log("[EVENT] " + (sender ? sender + " has sent an event: " : "") + message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (message, innerEx) {
|
error: function (message, innerEx) {
|
||||||
if (message) {
|
if (message) {
|
||||||
//log the message, attach innerEx information if it was passed
|
//log the message, attach innerEx information if it was passed
|
||||||
log("ERROR: " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : ""));
|
log("[ERROR] " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in a new issue