Skip to content

[core] Error reporting vs logging #3816

@oowekyala

Description

@oowekyala

In PMD6 all messages to report to a user are reported via a java.util.logging.Logger. In PMD 7, we should probably distinguish two different concerns:

  • Logging, for the purpose of diagnosing an execution (target audience: PMD developers)
  • Error reporting, for the purpose of telling the user what PMD is doing, or what the user should do (target audience: the end user)

A good log file should be very detailed, including info such as the class emitting the warning. OTOH, a good CLI output would tell the user what's happening without overwhelming them with details. It could have colors for instance. Separating these concerns in the implementation would make it easier to do a better job at each of them (polishing the user interface more, and making log files more detailed).

The rest of this ticket is a RFC about the details. Please feel free to edit, and treat this as a wiki page.

CLI switches

I'd like the default mode to be quiet, and to use a --verbose switch to show more output. The existing --debug switch could be used to show logs, to make a bug report. Maybe this should behave like so:

  • default:
$ pmd -d src -R ruleset/java/quickstart.xml
PMD 7.0.0 - built on 2022-07-14
Processing 50 files...
warning: at src/foo/A.java:20: Cannot find symbol 'org.foo.FooBar' 
warning: There were unresolved symbols, please check your --aux-classpath
Nothing to report.
  • --verbose:
$ pmd -d src -R ruleset/java/quickstart.xml
PMD 7.0.0 - built on 2022-07-14
Command line: pmd -d src -R ruleset/java/quickstart.xml
Processing 50 files...
Processing src/foo/A.java
warning: at src/foo/A.java:20: Cannot find symbol 'org.foo.FooBar'
19 |  import java.lang.String;
20 |  import org.foo.FooBar
             ^^^^^^^^^^^^^^ Cannot find symbol 'org.foo.FooBar'
21 |  import java.lang.String;
Processing src/foo/B.java
...

warning: There were unresolved symbols, please check your --aux-classpath
Nothing to report.
  • --debug: Like --verbose, but also forwards logger output to stdout
  • --verbose --debug: Same as --debug, but also enable level TRACE?

What goes where

  • Error reporting
    • warnings during ruleset parsing (deprecated rule, ...)
    • semantic errors/warnings?
      • "unresolved symbols" can be quite verbose, the warnings should probably be condensed
    • processing errors (rule failed on such node, cannot parse file X)
      • no stack trace, run with --debug to see it
    • ...
  • Logging
    • File collection (excluding file X, assigned language L to file F)
    • Tedious traces of all unresolved symbols
    • Stack traces
    • ...

Internals

  • SLF4J Logger is used for logging
  • Error reporting is done through another interface (maybe PmdReporter), an implementation can be given when calling PMD's entry point. So the CLI can use our implementation, and other tools like Ant can plug in their own logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:RFCA drafted proposal on changes to PMD, up for feedback form the team and communityan:enhancementAn improvement on existing features / rulesin:cliAffects the PMD Command Line Interface

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions