Browse Source

Merged feature/logging-spam-reduction into develop

shorten
benji7425 4 years ago
parent
commit
6cab2ebab8
  1. 1
      CHANGELOG.md
  2. 13
      log.js

1
CHANGELOG.md

@ -4,6 +4,7 @@
### 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
- Updated timer logic to only ever use a single timer, and share it between posting and reconnecting

13
log.js

@ -1,26 +1,31 @@
var console = require("console");
var latestLog = "";
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
console.log(new Date().toLocaleString() + " " + message);
}
}
module.exports = {
info: function (message) {
if (message)
log("INFO: " + message);
log("[INFO] " + message);
},
event: function (message, sender) {
//if we received a message, log it - include sender information if it was passed
if (message) {
log("EVENT: " + (sender ? sender + " has sent an event: " : "") + message);
log("[EVENT] " + (sender ? sender + " has sent an event: " : "") + message);
}
},
error: function (message, innerEx) {
if (message) {
//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…
Cancel
Save