Skip to content

[all] Use slf4j and SimpleLogger#3789

Merged
oowekyala merged 35 commits into
pmd:pmd/7.0.xfrom
adangel:pmd7-896-slf4j
Feb 27, 2022
Merged

[all] Use slf4j and SimpleLogger#3789
oowekyala merged 35 commits into
pmd:pmd/7.0.xfrom
adangel:pmd7-896-slf4j

Conversation

@adangel

@adangel adangel commented Feb 17, 2022

Copy link
Copy Markdown
Member

Describe the PR

  • Fixes [all] Use slf4j #896
  • Switching default debug level via CLI option "--debug" is supported. The solution need reflection though (Slf4jSimpleConfiguration) in order to not have a dependency on a specific logging implementation.
  • The ant integration is also working, but a bit hacky (Slf4jSimpleConfigurationForAnt). It basically intercepts the printstream that SimpleLogger is using. The old classes under net.sourceforge.pmd.util.logger are removed now (they were now unused).
  • pmd-dist provides the logger implementation, which is slf4j-simple. It also provides the default configuration (simplelogger.properties)
  • apex used to bring in logback, but it doesn't seem to be used (and luckily it's old and doesn't use slf4j 2.x ServiceLoader mechnism, but the old StaticBinder way - otherwise there would have been two logging implementations...). Maybe we should remove this dependency on master as well...
  • Only net.sourceforge.pmd.PMD is now migrated to use slf4j

Open Tasks:

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Support "--debug" flag for slf4j-simple
This is a hacky way: It reconfigures SimpleLogger to use
a special print stream. What ever is printed there is
forwarded to ant's project logger.

Removed the deprecated and now unused classes in
net.sourceforge.pmd.util.log.
@adangel adangel added this to the 7.0.0 milestone Feb 17, 2022
@adangel adangel linked an issue Feb 17, 2022 that may be closed by this pull request
8 tasks
@ghost

ghost commented Feb 18, 2022

Copy link
Copy Markdown
2 Messages
📖 Compared to pmd/7.0.x:
This changeset changes 32 violations,
introduces 31 new violations, 0 new errors and 0 new configuration errors,
removes 37 violations, 0 errors and 0 configuration errors.
Full report
📖 Compared to master:
This changeset changes 57268 violations,
introduces 34622 new violations, 7 new errors and 0 new configuration errors,
removes 138164 violations, 25 errors and 3 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 29 violations,
introduces 19 new violations, 0 new errors and 0 new configuration errors,
removes 27 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 57266 violations,
introduces 34622 new violations, 7 new errors and 0 new configuration errors,
removes 138166 violations, 25 errors and 3 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 49302 violations,
introduces 26826 new violations, 5 new errors and 0 new configuration errors,
removes 146082 violations, 25 errors and 3 configuration errors.
Full report
Compared to pmd/7.0.x:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 49302 violations,
introduces 26828 new violations, 5 new errors and 0 new configuration errors,
removes 146082 violations, 25 errors and 3 configuration errors.
Full report

Generated by 🚫 Danger

This is at least needed for apex jorje, but might be handy
for any other library that logs through jul.
Need to remove all handlers first, as java by default
adds a ConsoleLogger. The SLF4JBridgeHandler should be
the only handler registered.
adangel added a commit to pmd/build-tools that referenced this pull request Feb 18, 2022
@adangel adangel marked this pull request as ready for review February 18, 2022 18:46

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very cool!

Comment thread pmd-core/src/main/java/net/sourceforge/pmd/PMD.java Outdated
Comment thread pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java Outdated
Comment thread pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java Outdated
adangel and others added 2 commits February 19, 2022 10:44
Co-authored-by: Clément Fournier <clement.fournier76@gmail.com>
@adangel

adangel commented Feb 19, 2022

Copy link
Copy Markdown
Member Author

@oowekyala: I'll merge in the other PR (#3794) into this one - as it will only build as a whole. Then this PR will get a bit big unfortunately...

@adangel adangel mentioned this pull request Feb 19, 2022
6 tasks

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the large effort @adangel. I'm not sure what the best way to proceed is wrt conflicts with #3785. I'm inclined to merge this PR first, as it looks ready, and edit #3785 to minimize conflicts (but there will be some). Maybe I should prepare the merge into 7.0.x in a new PR

Comment thread pmd-dist/src/main/resources/scripts/run.sh Outdated
Comment thread pmd-dist/src/main/resources/scripts/run.sh Outdated
adangel and others added 5 commits February 26, 2022 11:29
Co-authored-by: Clément Fournier <clement.fournier76@gmail.com>
This theoretically allows to use
"-Dorg.slf4j.simpleLogger.defaultLogLevel=trace" manually

Still log the current default log level (verified in BinaryDistributionIT)
otherwise debug log level is enabled for later tests
@adangel

adangel commented Feb 26, 2022

Copy link
Copy Markdown
Member Author

Thanks for the large effort @adangel. I'm not sure what the best way to proceed is wrt conflicts with #3785. I'm inclined to merge this PR first, as it looks ready, and edit #3785 to minimize conflicts (but there will be some). Maybe I should prepare the merge into 7.0.x in a new PR

Sounds like a plan. The PmdLogger in #3785 is not really needed on master, so I'd suggest to remove it there and add it on 7.0.x after the merge.

Note: Currently in the pmd-java build in the unit tests, something is setting the default log level to DEBUG at some point and doesn't reset it. I see a lot of [main] DEBUG net.sourceforge.pmd.util.ClasspathClassLoader - Adding classpath entry: <.> loggings.... I didn't find the place yet, where this happens

This provides a default configuration that will be used
when resetting the logger configuration in CLITests or
PMDTaskTest. Without this, slf4j-simple will keep
the last configured default level. Now it will use the
default level configured in simplelogger.

Since pmd-test is not part of the distribution, this
configuration file has no effect for the binaries.
@adangel

adangel commented Feb 26, 2022

Copy link
Copy Markdown
Member Author

Note: Currently in the pmd-java build in the unit tests, something is setting the default log level to DEBUG at some point and doesn't reset it. I see a lot of [main] DEBUG net.sourceforge.pmd.util.ClasspathClassLoader - Adding classpath entry: <.> loggings.... I didn't find the place yet, where this happens

I solved it now by adding a default simplelogger.properties in pmd-test. This will be used, when we reset the configuration after a test, that messed with the configuration (to verify, that the --debug flag actually works). That way, it will now reset to whatever is configured in simplelogger.properties.

oowekyala added a commit that referenced this pull request Feb 27, 2022
@oowekyala oowekyala merged commit 7a0b20a into pmd:pmd/7.0.x Feb 27, 2022
@adangel adangel deleted the pmd7-896-slf4j branch February 28, 2022 18:29
@adangel adangel mentioned this pull request Jun 24, 2022
4 tasks
This was referenced Jan 13, 2023
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
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.

[all] Use slf4j

2 participants