Added basic spam reduction to log file
Added a check so it won't print the same message twice in a row
This commit is contained in:
parent
4c76852c65
commit
becf7c64be
|
@ -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
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…
Reference in New Issue