Skip to content

Conversation

@machadoit
Copy link
Contributor

It seems that when PMD is ran with an output file it logs the info messages to the STDOUT. But when returning results to the STDOUT does not do those logs (as most tools)

On the scope of our CLI, we usually propagate a temporary file location even if we output to the STDOUT, so when such file is propagated to PMD, we need to make sure to redirect the STDOUT to STDERR

Example

Processing files   0% [                  ] 0/2 (0:00:00) Violations:0, Errors:0^MProcessing files  50% [=========         ] 1/2 (0:00:00) Violations:0, Errors:0^MProcessing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1^MProcessing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1^MProcessing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1
Processing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1^MProcessing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1
Tool is not installed, installing...
Installing revive using go runtime...
{
  "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",

It seems that when PMD is ran with an output file it logs the info
messages to the STDOUT. But when returning results to the STDOUT
does not do those logs (as most tools)

On the scope of our CLI, we usually propagate a temporary file location
even if we output to the STDOUT, so when such file is propagated to
PMD, we need to make sure to redirect the STDOUT to STDERR

Example

```
Processing files   0% [                  ] 0/2 (0:00:00) Violations:0, Errors:0^MProcessing files  50% [=========         ] 1/2 (0:00:00) Violations:0, Errors:0^MProcessing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1^MProcessing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1^MProcessing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1
Processing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1^MProcessing files 100% [==================] 2/2 (0:00:00) Violations:0, Errors:1
Tool is not installed, installing...
Installing revive using go runtime...
{
  "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
```
@codacy-production
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.01% (target: -0.50%) 0.00% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f0a5bd7) 5760 1156 20.07%
Head commit (5fe8328) 5764 (+4) 1156 (+0) 20.06% (-0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#186) 6 0 0.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

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

This PR fixes an issue where PMD outputs progress logs to STDOUT when writing analysis results to a file, which pollutes the output stream. The fix redirects STDOUT to STDERR when an output file is specified, ensuring clean separation of analysis results from progress logs.

Key Changes

  • Added conditional logic to redirect cmd.Stdout to os.Stderr when PMD writes to an output file
  • Maintained cmd.Stdout = os.Stdout behavior when no output file is specified
  • Minor reordering of command setup (swapped order of Stderr and Dir assignment, no functional impact)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@machadoit machadoit merged commit 2651163 into main Dec 9, 2025
14 of 16 checks passed
@machadoit machadoit deleted the logs-std-out-pmd-CF-2115 branch December 9, 2025 15:36
@codacy-production
Copy link

Codacy's Analysis Summary

0 new issue (≤ 1 medium issue)
0 new security issue (≤ 0 issue)
0 complexity
0 duplications

Review Pull Request in Codacy →

AI Reviewer available: add the codacy-review label to get contextual insights without leaving GitHub.

1 similar comment
@codacy-production
Copy link

Codacy's Analysis Summary

0 new issue (≤ 1 medium issue)
0 new security issue (≤ 0 issue)
0 complexity
0 duplications

Review Pull Request in Codacy →

AI Reviewer available: add the codacy-review label to get contextual insights without leaving GitHub.

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.

3 participants