Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON formatter plugin #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ configs:
plugins: []
aliases: {}
logFilename: 'multimeter.log'
json: false
```

### Connecting to the official server
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions plugins/json.js
Original file line number Diff line number Diff line change
@@ -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
}
}
});
};
3 changes: 2 additions & 1 deletion src/multimeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down