question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to format `debug` as JSON output

See original GitHub issue

I’d like there to be an option (controllable using environment variables) that would make debug module print JSON output instead of plain text.

This at the moment can be achieved using a module such as debug-to-json (@ping yoshuawuyts). The problem with the pipe solution is that it is not always easy to modify the command used to start the program (e.g. How to append an argument to a container command?).

Maybe I am doing something wrong, but (in a large deployment) logs coming via debug are quite useless (“large deployment” being a Kubernetes cluster with filebeat + ELK used for logging). [I suppose it is possible to reconize debug output in logstash and convert it to JSON?]

Being able to configure debug output with environment variable would greatly alleviate the difficulty of log processing here, e.g.

DEBUG_FORMAT=json

The other thing to note here is that certain log aggregation methods (filebeat) require that logs come in one-per-line. Plain text output does not guarantee this; JSON can.

Furthermore, the JSON format could be used to supplement debug output with meta information such as package name, version. This can be a controllable option via environment variables too.

I’d be happy to raise a PR.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
gajuscommented, Apr 18, 2017

If you really want to depend on overriding the output method, then use a global variable, e.g.

// debug-format.js
global.visionmediaDebugOut = () => {};

Then whatever app that wants to override the out method would need to include this script prior to executing any code, e.g. node -r debug-format.js my-app.js.

Unlike the proposed approach, this approach can be work with multiple versions of debug in a backwards compatible way.

I don’t think thats a right approach. It is an overkill. Simply allowing to output content in JSON format using ENV as configuration would be enough.

1reaction
gajuscommented, Apr 18, 2017

Well, overriding the functionality of out is hardly a fix here. If I need to override something, I’d rather use a logging framework such as bunyan or winston. The convenience of debug is that it is a convention driven, runtime configurable logging tool. If I need to override something, then it is just another logging framework.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add ability to format debug as JSON output #442 - GitHub
I'd like there to be an option (controllable using environment variables) that would make debug module print JSON output instead of plain ...
Read more >
Get object as JSON in IntelliJ Idea from debugger
Add a new way to view objects in Intellij debugger as json by · Click OK · Now when you choose Copy Value...
Read more >
Customize build debug tasks with JSON files - Visual Studio ...
Learn how to customize tasks to provide some configuration details to run and debug a codebase that Visual Studio doesn't recognize.
Read more >
System.debug(JSON.Serialize(o)) Not longer shows full string
For the longest time I have been using System.debug(JSON.Serialize(o)) to output objects to the debug log for troubleshooting purposes.
Read more >
How to Debug a JSON Save Issue (errata added) - YouTube
A tutorial on how to debug a JSON save issue and verify your data's integrity.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found