You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-27 06:23:53 +01:00
restructure, bugfixes
This commit is contained in:
74
server/console.js
Normal file
74
server/console.js
Normal file
@@ -0,0 +1,74 @@
|
||||
const verboseMode = process.argv.includes('--debug');
|
||||
const verboseModeFfmpeg = process.argv.includes('--ffmpegdebug');
|
||||
|
||||
const getCurrentTime = () => {
|
||||
const currentTime = new Date();
|
||||
const hours = currentTime.getHours().toString().padStart(2, '0');
|
||||
const minutes = currentTime.getMinutes().toString().padStart(2, '0');
|
||||
return `\x1b[90m[${hours}:${minutes}]\x1b[0m`;
|
||||
};
|
||||
|
||||
const MESSAGE_PREFIX = {
|
||||
DEBUG: "\x1b[36m[DEBUG]\x1b[0m",
|
||||
ERROR: "\x1b[31m[ERROR]\x1b[0m",
|
||||
FFMPEG: "\x1b[36m[FFMPEG]\x1b[0m",
|
||||
INFO: "\x1b[32m[INFO]\x1b[0m",
|
||||
WARN: "\x1b[33m[WARN]\x1b[0m",
|
||||
};
|
||||
|
||||
// Initialize an array to store logs
|
||||
const logs = [];
|
||||
const maxLogLines = 250;
|
||||
|
||||
const logDebug = (...messages) => {
|
||||
if (verboseMode) {
|
||||
const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.DEBUG} ${messages.join(' ')}`;
|
||||
logs.push(logMessage);
|
||||
if (logs.length > maxLogLines) {
|
||||
logs.shift();
|
||||
}
|
||||
console.log(logMessage);
|
||||
}
|
||||
};
|
||||
|
||||
const logError = (...messages) => {
|
||||
const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.ERROR} ${messages.join(' ')}`;
|
||||
logs.push(logMessage);
|
||||
if (logs.length > maxLogLines) {
|
||||
logs.shift();
|
||||
}
|
||||
console.log(logMessage);
|
||||
};
|
||||
|
||||
const logFfmpeg = (...messages) => {
|
||||
if (verboseModeFfmpeg) {
|
||||
const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.FFMPEG} ${messages.join(' ')}`;
|
||||
logs.push(logMessage);
|
||||
if (logs.length > maxLogLines) {
|
||||
logs.shift();
|
||||
}
|
||||
console.log(logMessage);
|
||||
}
|
||||
};
|
||||
|
||||
const logInfo = (...messages) => {
|
||||
const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.INFO} ${messages.join(' ')}`;
|
||||
logs.push(logMessage);
|
||||
if (logs.length > maxLogLines) {
|
||||
logs.shift();
|
||||
}
|
||||
console.log(logMessage);
|
||||
};
|
||||
|
||||
const logWarn = (...messages) => {
|
||||
const logMessage = `${getCurrentTime()} ${MESSAGE_PREFIX.WARN} ${messages.join(' ')}`;
|
||||
logs.push(logMessage);
|
||||
if (logs.length > maxLogLines) {
|
||||
logs.shift();
|
||||
}
|
||||
console.log(logMessage);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
logError, logDebug, logFfmpeg, logInfo, logWarn, logs
|
||||
};
|
||||
Reference in New Issue
Block a user