Add stripping of instance paths in Factorio log

Add option defaulting to true to strip instance directory paths printed
into the Factorio log down to be relative to the instance.
This commit is contained in:
Hornwitser committed 2020-11-09 15:57:46 +01:00
1 parent 63a656cd61
commit 67654fdf85
5 files changed
+65 -1

No files matched your search

+1
View File
@@ -46,6 +46,7 @@ Version 2.0.0
player data.
- Added synchronization of in-game adminlist, banlist and whitelist to
Clusterio core. Previously this was handled by the playerManager plugin.
- Added stripping of long paths in the Factorio server log.
### Changes
+20
View File
@@ -280,6 +280,26 @@ here overrides the properties there.
Defaults to {"tags":["clusterio"],"auto_pause":false}.
### factorio.strip_paths
Strip down absolute paths in the server log going to files inside the
instance directory such that they are relative to the instance
directory. This improves the signal to noise ratio of the log.
Sample output when disabled:
0.487 Loading map /srv/clusterio/instances/test/saves/world.zip: 2615888 bytes.
0.614 Checksum for script /srv/clusterio/instances/test/temp/currently-playing/control.lua: 2390553941
1.277 Script @/srv/clusterio/instances/test/temp/currently-playing/modules/example/test.lua:7: Example log line.
Sample output when enabled:
0.487 Loading map saves/world.zip: 2615888 bytes.
0.614 Checksum for script temp/currently-playing/control.lua: 2390553941
1.277 Script @modules/example/test.lua:7: Example log line.
Defaults to true
### factorio.sync_adminlist
Synchronize in-game admin list with admin status of the users in
+6
View File
@@ -250,6 +250,12 @@ FactorioGroup.define({
"auto_pause": false,
},
});
FactorioGroup.define({
name: "strip_paths",
description: "Strip down instance paths in the log",
type: "boolean",
initial_value: true,
});
FactorioGroup.define({
name: "sync_adminlist",
description: "Synchronize adminlist with master server",
+37 -1
View File
@@ -12,6 +12,22 @@ const rconClient = require("rcon-client");
const libErrors = require("@clusterio/lib/errors");
/**
* Escapes text for inclusion in a RegExp
*
* Adds \ character in front of special meta characters in the passsed in
* text so that it can be embedded into a RegExp and only match the text.
*
* See https://stackoverflow.com/a/9310752
*
* @param {string} text - Text to escape RegExp meta chars in.
* @returns {string} escaped text.
* @inner
*/
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
/**
* Determines the version of Factorio the datadir is pointing to by
* reading the changelog.txt in it.
@@ -497,6 +513,7 @@ class FactorioServer extends events.EventEmitter {
* @param {number} options.gamePort - UDP port to host game on.
* @param {number} options.rconPort - TCP port to use for RCON.
* @param {string} options.rconPassword - Password use for RCON.
* @param {boolean} options.stripPaths - Strip paths in the console.
*/
constructor(factorioDir, writeDir, options) {
super();
@@ -523,6 +540,19 @@ class FactorioServer extends events.EventEmitter {
this._rconReady = false;
this._gameReady = false;
if (options.stripPaths) {
let chars = new Set(this.writePath("temp"));
chars.delete(":"); // Having a colon could lead to matching the line number
chars = [...chars].join("");
this._stripRegExp = new RegExp(
`(${escapeRegExp(this.writePath("temp", "currently-playing", path.sep))})|` +
`(${escapeRegExp(this.writePath(path.sep))})|` +
`(\\.\\.\\.[${chars}]*?currently-playing\\${path.sep})`,
"g"
);
}
// Array of possible causes for an unexpected shutdown
this._unexpected = [];
@@ -606,7 +636,13 @@ class FactorioServer extends events.EventEmitter {
this.emit(source, line);
let output = parseOutput(line.toString("utf-8"), source);
line = line.toString("utf-8");
if (this._stripRegExp) {
line = line.replace(this._stripRegExp, "");
}
let output = parseOutput(line, source);
heuristicLoop: for (let heuristic of outputHeuristics) {
for (let [name, expected] of Object.entries(heuristic.filter)) {
if (!Object.hasOwnProperty.call(output, name)) {
+1
View File
@@ -135,6 +135,7 @@ class Instance extends libLink.Link{
rconPort: this.config.get("factorio.rcon_port"),
rconPassword: this.config.get("factorio.rcon_password"),
enableWhitelist: this.config.get("factorio.enable_whitelist"),
stripPaths: this.config.get("factorio.strip_paths"),
};
this._running = false;