Skip to content

Use plain logging for subcommands and require subcommands first - #2196

Open
waldekmastykarz wants to merge 2 commits into
dotnet:mainfrom
waldekmastykarz:plain-logging-subcommands
Open

waldekmastykarz wants to merge 2 commits into
dotnet:mainfrom
waldekmastykarz:plain-logging-subcommands

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Uses plain (undecorated) console output for all subcommands and keeps the decorated, level-labeled output only for the root command that monitors traffic.

Before, every line of e.g. devproxy api show was prefixed with info. Now:

  • Subcommands print messages as-is. Warnings and errors get a short warning: / error: prefix.
  • The root command (proxy) output is unchanged, so devproxy logs and detached log parsing are unaffected.

Subcommands must come first

To reliably tell the root command from subcommands before plugins (which can contribute their own subcommands) are loaded, subcommands must now be the first argument. Options placed before a subcommand are rejected with exit code 2:

$ devproxy --log-level debug api show
Options must follow the subcommand. Use: devproxy api show [options]

Recursive options (--log-level, --output, ...) keep working after the subcommand. This simplifies the stdio/validate/plugin invocation detection, which no longer needs to skip leading option values.

Changes

  • ProxyConsoleFormatterOptions.PlainOutput, enabled for subcommand logging, config and standalone plugin commands
  • DevProxyCommand.GetLeadingOptionsError enforces the subcommand-first rule (text and JSON output)
  • Simplified IsStdioSubcommand, IsValidateInvocation, IsPluginCommand

Notes

  • --env before stdio (undocumented) is no longer supported
  • devproxy --detach api show now fails with the new error instead of running api show

Subcommands such as 'devproxy api show' now print plain text without
level labels; the decorated output is kept for the root command that
monitors traffic. Options placed before a subcommand are now rejected,
so the root command can be detected reliably from the first argument,
even for subcommands contributed by plugins.

Co-authored-by: Copilot App <[email protected]>
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner November 28, 2026 08:24
Copilot AI balanced review requested due to automatic review settings November 28, 2026 08:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Configuration loading can preempt command-order errors and standalone validation when recursive options intervene, while logging thresholds can suppress usage diagnostics.

3 open issues
What changed in this PR

This PR separates subcommand output from Dev Proxy’s traffic-monitoring logs: subcommands use plain messages, while the root command retains decorated logging. It also introduces a subcommand-first argument rule.

Changes:

  • Enables plain logging for subcommands and standalone plugin and validation commands.
  • Adds ordering errors for options before subcommands and simplifies invocation detection.
  • Updates tests for plain output and the new argument-ordering behavior.
File Description
DevProxy/​Logging/​ProxyConsoleFormatterOptions.cs Adds the plain-output option.
DevProxy/​Logging/​ProxyConsoleFormatter.cs Supports plain messages with short diagnostic prefixes.
DevProxy/​Extensions/​ILoggingBuilderExtensions.cs Enables plain logging for subcommands.
DevProxy/​Commands/​PluginCommand.cs Enables plain standalone plugin output.
DevProxy/​Commands/​DevProxyCommand.cs Adds ordering checks and simplifies command detection.
DevProxy/​Commands/​ConfigCommand.cs Enables plain standalone validation output.
DevProxy.Tests/​ProxyConsoleFormatterTests.cs Tests plain messages and diagnostic prefixes.
DevProxy.Tests/​LoggingConfigurationTests.cs Tests root versus subcommand formatting selection.
DevProxy.Tests/​DevProxyConfigOptionsTests.cs Removes coverage for leading environment options before stdio.
DevProxy.Tests/​DevProxyCommandTests.cs Tests subcommand-first detection and ordering errors.
DevProxy.Tests/​ConfigValidateTests.cs Updates validation cases for command-first arguments.

Review effort: Balanced

Comment thread DevProxy/Commands/DevProxyCommand.cs Resolved
Comment thread DevProxy/Commands/DevProxyCommand.cs Resolved
Comment thread DevProxy/Commands/DevProxyCommand.cs Resolved
- Allow recursive options between 'config' and 'validate' for standalone validation
- Show the options-order error regardless of the configured log level

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the subcommand-output and command-ordering changes.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants