1
0
Fork 0
forked from svrjs/svrjs

Disable console.log for non-TTY stdout

This commit is contained in:
Dorian Niemiec 2024-08-23 21:58:26 +02:00
parent 00d01e7cf5
commit 881502d897

View file

@ -8,6 +8,13 @@ const version = svrjsInfo.version;
//const parseURL = require("./utils/urlParser.js"); //const parseURL = require("./utils/urlParser.js");
//const fixNodeMojibakeURL = require("./utils/urlMojibakeFixer.js"); //const fixNodeMojibakeURL = require("./utils/urlMojibakeFixer.js");
let inspector = undefined;
try {
inspector = require("inspector");
} catch (err) {
// Don't use inspector
}
// Create log, mods and temp directories, if they don't exist. // Create log, mods and temp directories, if they don't exist.
if (!fs.existsSync(__dirname + "/log")) fs.mkdirSync(__dirname + "/log"); if (!fs.existsSync(__dirname + "/log")) fs.mkdirSync(__dirname + "/log");
if (!fs.existsSync(__dirname + "/mods")) fs.mkdirSync(__dirname + "/mods"); if (!fs.existsSync(__dirname + "/mods")) fs.mkdirSync(__dirname + "/mods");
@ -15,6 +22,23 @@ if (!fs.existsSync(__dirname + "/temp")) fs.mkdirSync(__dirname + "/temp");
const serverconsoleConstructor = require("./utils/serverconsole.js"); const serverconsoleConstructor = require("./utils/serverconsole.js");
let inspectorURL = undefined;
try {
if (inspector) {
inspectorURL = inspector.url();
}
} catch (err) {
// Failed to get inspector URL
}
if (!process.stdout.isTTY && !inspectorURL) {
// When stdout is not a terminal and not attached to an Node.JS inspector, disable it to improve performance of SVR.JS
console.log = function () {};
process.stdout.write = function () {};
process.stdout._write = function () {};
process.stdout._writev = function () {};
}
let configJSON = {}; let configJSON = {};
// TODO: configuration from config.json // TODO: configuration from config.json