Formatting Pass 2 Electric Boogaloo

This commit is contained in:
Michael 2023-09-13 08:41:47 -04:00
parent 0e88fe0fce
commit 8650468bd9
2 changed files with 53 additions and 53 deletions

View file

@ -7,21 +7,21 @@
// Enum list of severity levels
const logLevels = {
DEBUG: 0,
INFO: 1,
WARN: 2,
ERROR: 3,
DEBUG: 0,
INFO: 1,
WARN: 2,
ERROR: 3,
};
// Enum list of text colors
const textColor = {
White: '\x1b[97m',
Gray: '\x1b[37m',
Yellow: '\x1b[33m',
Red: '\x1b[91m',
Blue: '\x1b[96m',
Green: '\x1b[92m',
Reset: '\x1b[0m',
White: '\x1b[97m',
Gray: '\x1b[37m',
Yellow: '\x1b[33m',
Red: '\x1b[91m',
Blue: '\x1b[96m',
Green: '\x1b[92m',
Reset: '\x1b[0m',
};
// Get the current Date and Time
@ -30,43 +30,43 @@ const datetime = '[' + ('0' + (date_time.getMonth() + 1)).slice(-2) + '/' + ('0'
// Add color to the text passed through - If a text manip util is made, move this there
const colorText = function(message, color) {
return color + message + textColor.Reset;
return color + message + textColor.Reset;
};
// Print log message to console based on severity level
const log = function(logLevel, message) {
// Used in the event the message is an error: see case 3
const lines = message.toString().split('\n');
// Used in the event the message is an error: see case 3
const lines = message.toString().split('\n');
switch (logLevel) {
case 0:
console.log(datetime + ' ' + colorText('[DEBUG]', textColor.Gray) + ' ' + message);
break;
case 1:
console.log(datetime + ' ' + colorText('[INFO]', textColor.White) + ' ' + message);
break;
case 2:
console.log(datetime + ' ' + colorText('[WARN]', textColor.Yellow) + ' ' + message);
break;
case 3:
// Errors tend to have multiple lines, handle them specially to include the first two.
console.log(datetime + ' ' + colorText('[ERROR]', textColor.Red) + ' ' + lines[0]);
switch (logLevel) {
case 0:
console.log(datetime + ' ' + colorText('[DEBUG]', textColor.Gray) + ' ' + message);
break;
case 1:
console.log(datetime + ' ' + colorText('[INFO]', textColor.White) + ' ' + message);
break;
case 2:
console.log(datetime + ' ' + colorText('[WARN]', textColor.Yellow) + ' ' + message);
break;
case 3:
// Errors tend to have multiple lines, handle them specially to include the first two.
console.log(datetime + ' ' + colorText('[ERROR]', textColor.Red) + ' ' + lines[0]);
// If the error only has 1 line, don't try to read a second one
if (lines[1] != null) {
console.log(datetime + ' ' + colorText('[ERROR]', textColor.Red) + ' | ' + lines[1].trim());
}
// If the error only has 1 line, don't try to read a second one
if (lines[1] != null) {
console.log(datetime + ' ' + colorText('[ERROR]', textColor.Red) + ' | ' + lines[1].trim());
}
break;
default:
console.log(datetime + ' ' + colorText('[INFO]', textColor.White) + ' ' + message);
break;
}
break;
default:
console.log(datetime + ' ' + colorText('[INFO]', textColor.White) + ' ' + message);
break;
}
};
module.exports = {
logLevels,
textColor,
colorText,
log,
logLevels,
textColor,
colorText,
log,
};

View file

@ -6,35 +6,35 @@
const io = require('@pm2/io');
const interactionErrors = io.counter({
name: 'Interaction Errors (Since last restart)',
name: 'Interaction Errors (Since last restart)',
});
const interactionSuccessCounter = io.counter({
name: 'Interaction Successful Runs (Since last restart)',
name: 'Interaction Successful Runs (Since last restart)',
});
const interactionSuccessMeter = io.meter({
name: 'Successful Interactions per Second',
name: 'Successful Interactions per Second',
});
const websocketHeartbeatHist = io.histogram({
name: 'Avg. Websocket Heartbeat (ms) / 5 min.',
measurement: 'mean',
name: 'Avg. Websocket Heartbeat (ms) / 5 min.',
measurement: 'mean',
});
const serverCount = io.metric({
name : 'Server Count',
name : 'Server Count',
});
const interactionSuccess = function() {
interactionSuccessCounter.inc();
interactionSuccessMeter.mark();
interactionSuccessCounter.inc();
interactionSuccessMeter.mark();
};
module.exports = {
io,
interactionErrors,
interactionSuccess,
websocketHeartbeatHist,
serverCount,
io,
interactionErrors,
interactionSuccess,
websocketHeartbeatHist,
serverCount,
};