From 60ee4b2c8634ab4cfb1e8a069c06b49b109575a3 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:41:19 +0000 Subject: [PATCH] Add config option for console logging --- packages/host/src/Instance.ts | 1 + packages/host/src/server.ts | 7 +++++++ packages/lib/src/config/definitions.ts | 7 +++++++ test/integration/clusterio.js | 12 ++++++++++++ 4 files changed, 27 insertions(+) diff --git a/packages/host/src/Instance.ts b/packages/host/src/Instance.ts index 71a96343..007affa5 100644 --- a/packages/host/src/Instance.ts +++ b/packages/host/src/Instance.ts @@ -218,6 +218,7 @@ export default class Instance extends lib.Link { enableWhitelist: this.config.get("factorio.enable_whitelist"), enableAuthserverBans: this.config.get("factorio.enable_authserver_bans"), verboseLogging: this.config.get("factorio.verbose_logging"), + consoleLogging: this.config.get("factorio.console_logging"), stripPaths: this.config.get("factorio.strip_paths"), maxConcurrentCommands: this.config.get("factorio.max_concurrent_commands"), shutdownTimeoutMs: this.config.get("factorio.shutdown_timeout") * 1000, diff --git a/packages/host/src/server.ts b/packages/host/src/server.ts index 1658232f..7ff2ac20 100644 --- a/packages/host/src/server.ts +++ b/packages/host/src/server.ts @@ -438,6 +438,8 @@ export interface FactorioServerOptions { enableAuthserverBans?: boolean, /** Enable verbose logging. */ verboseLogging?: boolean, + /** Enable console logging. */ + consoleLogging?: boolean, /** Strip paths in the console. */ stripPaths?: boolean, /** @@ -486,6 +488,8 @@ export class FactorioServer extends events.EventEmitter { enableAuthserverBans: boolean; /** Enable verbose logging */ verboseLogging: boolean; + /** Enable console logging */ + consoleLogging: boolean; _shutdownTimeoutMs = 0; _stopTimeoutId?: ReturnType; @@ -541,6 +545,8 @@ export class FactorioServer extends events.EventEmitter { this.enableAuthserverBans = options.enableAuthserverBans || false; /** Enable verbose logging */ this.verboseLogging = options.verboseLogging || false; + /** Enable console logging */ + this.consoleLogging = options.consoleLogging || false; /** Maximum number of RCON commands transmitted in parallel on the RCON connection */ this.maxConcurrentCommands = options.maxConcurrentCommands || 5; if (options.shutdownTimeoutMs !== undefined) { @@ -973,6 +979,7 @@ export class FactorioServer extends events.EventEmitter { ...(this.enableWhitelist ? ["--use-server-whitelist"] : []), ...(this.enableAuthserverBans ? ["--use-authserver-bans"] : []), ...(this.verboseLogging ? ["--verbose"] : []), + ...(this.consoleLogging ? ["--console-log", this.writePath("console.log")] : []), ], { detached: true, diff --git a/packages/lib/src/config/definitions.ts b/packages/lib/src/config/definitions.ts index e7f7406d..40a33ea6 100644 --- a/packages/lib/src/config/definitions.ts +++ b/packages/lib/src/config/definitions.ts @@ -333,6 +333,7 @@ export interface InstanceConfigFields { "factorio.enable_authserver_bans": boolean; "factorio.settings": Record; "factorio.verbose_logging": boolean; + "factorio.console_logging": boolean; "factorio.strip_paths": boolean; "factorio.sync_adminlist": "enabled" | "disabled" | "bidirectional"; "factorio.sync_whitelist": "enabled" | "disabled" | "bidirectional"; @@ -488,6 +489,12 @@ export class InstanceConfig extends classes.Config { type: "boolean", initialValue: false, }, + "factorio.console_logging": { + description: "Enable console logging to a separate file, useful for 3rd party integrations", + restartRequired: true, + type: "boolean", + initialValue: false, + }, "factorio.strip_paths": { description: "Strip down instance paths in the log", restartRequired: true, diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index a6cba45a..2028f6ab 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -434,6 +434,18 @@ describe("Integration of Clusterio", function() { await execCtl("instance start test --save world.zip"); await checkInstanceStatus(44, "running"); }); + it("allows having a separate console log", async function() { + slowTest(this); + await execCtl("instance stop 44"); + await execCtl("instance config set 44 factorio.console_logging true"); + await execCtl("instance start test"); + await checkInstanceStatus(44, "running"); + const checkMessage = `check${Date.now()}`; + await sendRcon(44, checkMessage); + const consoleLog = await fs.readFile(path.join("temp", "test", "instances", "test", "console.log")); + assert(consoleLog.includes(checkMessage)); + await execCtl("instance config set 44 factorio.console_logging false"); + }); it("copies the save if an autosave is the target", async function() { slowTest(this); await execCtl("instance stop 44");