Skip to content

Fix text output returned despite --output json in detached mode#1588

Open
Copilot wants to merge 6 commits intomainfrom
copilot/fix-output-json-bug
Open

Fix text output returned despite --output json in detached mode#1588
Copilot wants to merge 6 commits intomainfrom
copilot/fix-output-json-bug

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

StartDetachedProcessAsync in Program.cs writes directly to Console.Out/Console.Error before the DI container and logging infrastructure are initialized, bypassing JsonConsoleFormatter entirely. The --output json flag was ignored.

  • Added IsJsonOutputRequested helper that parses --output json from raw args (same pattern as ConfigCommand.RunValidateStandaloneAsync)
  • Success output uses the same JSONL envelope as JsonConsoleFormatter: {"type":"result","data":{pid,apiUrl,logFile},"timestamp":"..."}
  • Error paths emit JSONL log entries to stderr: {"type":"log","level":"error","message":"...","timestamp":"..."}
  • All JSON output is single-line JSONL for consistent machine parsing across commands

With --output json (success):

{"type":"result","data":{"pid":6456,"apiUrl":"http://127.0.0.1:8897","logFile":"/Users/scope/.local/dev-proxy/logs/devproxy-6456-2026-03-05.log"},"timestamp":"2026-03-05T14:22:42.0000000Z"}

With --output json (error):

{"type":"log","level":"error","message":"Dev Proxy is already running (PID: 6456). Use 'devproxy stop' to stop it first.","timestamp":"2026-03-05T14:22:42.0000000Z"}

Without (unchanged):

Dev Proxy started in background.

  PID:       6456
  API URL:   http://127.0.0.1:8897
  Log file:  /Users/scope/.local/dev-proxy/logs/devproxy-6456-2026-03-05.log
Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: text output returned despite --output json</issue_title>
<issue_description>When you start Dev Proxy using devproxy --port 0 --output json --detach it shows the following output:

Dev Proxy started in background.

  PID:       6456
  API URL:   http://127.0.0.1:8897
  Log file:  C:\Users\scope\AppData\Local\dev-proxy\logs\devproxy-6456-2026-03-05-14-22-42.log

Use 'devproxy status' to check status.
Use 'devproxy logs' to view logs.
Use 'devproxy stop' to stop.

Despite output being set to json the actual output is plain text.</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix text output returned despite --output json Fix text output returned despite --output json in detached mode Mar 5, 2026
@waldekmastykarz waldekmastykarz marked this pull request as ready for review March 5, 2026 14:40
@waldekmastykarz waldekmastykarz requested a review from a team as a code owner March 5, 2026 14:40
Copilot AI review requested due to automatic review settings March 5, 2026 14:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes detached-mode startup output so devproxy --detach --output json returns JSON instead of always returning text, even before DI/logging is initialized.

Changes:

  • Detects --output json from raw args in StartDetachedProcessAsync.
  • Emits JSON on stdout for successful detached startup and JSON on stderr for error paths.
  • Adds IsJsonOutputRequested helper and uses ProxyUtils.JsonSerializerOptions for serialization.

You can also share your feedback on Copilot code review. Take the survey.

@waldekmastykarz
Copy link
Collaborator

@copilot apply changes based on the comments in this thread

Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 5, 2026

@copilot apply changes based on the comments in this thread

Applied in a65e725. JSON output now uses the same JSONL envelope format as JsonConsoleFormatter:

  • Success: {"type":"result","data":{"pid":6456,"apiUrl":"http://127.0.0.1:8897","logFile":"..."},"timestamp":"..."}
  • Errors: {"type":"log","level":"error","message":"...","timestamp":"..."}

All output is single-line JSONL for consistent machine parsing across commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: text output returned despite --output json

3 participants