Merged feature/logging-spam-reduction into develop

This commit is contained in:
benji7425 2017-01-08 06:39:15 +00:00
commit 6cab2ebab8
2 changed files with 10 additions and 4 deletions

View file

@ -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
View file

@ -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) : ""));
} }
} }
}; };