Add logging system based on winston

Add winston based logger for master, slave, ctl, lib, and web_ui code.
Logging done from slaves and instances are sent to the master server and
tagged with the instance and/or slave it originated from.  This allows
for example error messages to propagate back to the source that iniated
the action.  The master server also stores the log to allow it to be
queried at a later point.  For slaves a copy of the slave's log is also
stored locally.
This commit is contained in:
Hornwitser committed 2020-11-27 17:51:07 +01:00
1 parent 8f176c969b
commit 957983d8a5
47 files changed
+992 -513

No files matched your search

+11 -13
View File
@@ -4,19 +4,17 @@ const fs = require("fs-extra");
const libPlugin = require("@clusterio/lib/plugin");
const libLuaTools = require("@clusterio/lib/lua_tools");
function unexpectedError(err) {
console.log("Unexpected error in subspace_storage");
console.log("------------------------------------");
console.log(err);
}
class InstancePlugin extends libPlugin.BaseInstancePlugin {
unexpectedError(err) {
this.logger.error(`Unexpected error:\n${err.stack}`);
}
async init() {
this.instance.server.on("ipc-subspace_storage:output", (output) => {
this.provideItems(output).catch(unexpectedError);
this.provideItems(output).catch(err => this.unexpectedError(err));
});
this.instance.server.on("ipc-subspace_storage:orders", (orders) => {
this.requestItems(orders).catch(unexpectedError);
this.requestItems(orders).catch(err => this.unexpectedError(err));
});
}
@@ -24,7 +22,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
this.pingId = setInterval(() => {
this.sendRcon(
"/sc __subspace_storage__ global.ticksSinceMasterPinged = 0", true
).catch(unexpectedError);
).catch(err => this.unexpectedError(err));
}, 5000);
let response = await this.info.messages.getStorage.send(this.instance);
@@ -45,8 +43,8 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
});
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
console.log("Exported the following to master:");
console.log(items);
this.logger.verbose("Exported the following to master:");
this.logger.verbose(JSON.stringify(items));
}
}
@@ -63,8 +61,8 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
}
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
console.log("Imported following from master:");
console.log(response.items);
this.logger.verbose("Imported following from master:");
this.logger.verbose(JSON.stringify(response.items));
}
let itemsJson = libLuaTools.escapeString(JSON.stringify(response.items));