diff --git a/README.md b/README.md index 8079f77..9d28a80 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ configs: plugins: [] aliases: {} logFilename: 'multimeter.log' + json: false ``` ### Connecting to the official server @@ -176,6 +177,19 @@ configs: errorLogFilename: "screepsErrors.log" ``` +### Plugin: json + +When the log line is a JSON it will format it like readable JSON. + +Default setting for this plugin: +``` +configs: + multimeter: + json: false +``` + +To enable change to `true` + ## Contributing If you have feedback, bugs, or feature requests for multimeter, don't hesitate to look through [the issues](https://github.com/CGamesPlay/screeps-multimeter/issues) and add your thoughts. Please search to see if someone else has already filed a related issue before you submit a new one. diff --git a/plugins/json.js b/plugins/json.js new file mode 100644 index 0000000..fc69891 --- /dev/null +++ b/plugins/json.js @@ -0,0 +1,15 @@ +const parse5 = require('parse5'); + +module.exports = function(multimeter) { + multimeter.console.on("addLines", function(event) { + let jsonFormattingEnabled = multimeter.config.json; + if (jsonFormattingEnabled && (event.type === "log" || event.type === "result")) { + try { + let obj = JSON.parse(event.line); + event.line = JSON.stringify(obj, null, 1) + } catch (e) { + // not a json line + } + } + }); +}; diff --git a/src/multimeter.js b/src/multimeter.js index c71b03f..54d1543 100644 --- a/src/multimeter.js +++ b/src/multimeter.js @@ -18,7 +18,8 @@ const BUILTIN_PLUGINS = [ "../plugins/html.js", "../plugins/pause", "../plugins/filter", - "../plugins/log" + "../plugins/log", + "../plugins/json" ]; class Gauges extends blessed.layout {