PMD usesslf4j as the logging API internally. Logging can be done also in(Java-based) rules.
In order to log, get a logger. Usually the logger is stored in a static final field calledLOG:
privatestaticfinalLoggerLOG=LoggerFactory.getLogger(MyClass.class);If you need log output in unit tests, make sure to have a logging implementation on the test classpath.E.g. you can add (if it is missing) the following dependency:
<dependency><groupId>org.slf4j</groupId><artifactId>slf4j-simple</artifactId><scope>test</scope></dependency>To configure the logging, create the filesrc/test/resources/simplelogger.properties:
org.slf4j.simpleLogger.logFile=System.errorg.slf4j.simpleLogger.showDateTime=falseorg.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd'T'HH:mm:ss.SSSXXXorg.slf4j.simpleLogger.showThreadName=trueorg.slf4j.simpleLogger.showThreadId=falseorg.slf4j.simpleLogger.showLogName=trueorg.slf4j.simpleLogger.showShortLogName=falseorg.slf4j.simpleLogger.levelInBrackets=false# Default log level for all loggers# Must be one of "trace", "debug", "info", "warn", "error" or "off"# Will be changed by "--debug" command line optionorg.slf4j.simpleLogger.defaultLogLevel=info# configure logging detail level for a single logger.# Must be one of "trace", "debug", "info", "warn", "error" or "off"#org.slf4j.simpleLogger.log.net.sourceforge.pmd.PMD=debug#org.slf4j.simpleLogger.log.com.example.rules.MyRule=debugIf you want to verify log output in unit tests, you can useorg.junit.contrib.java.lang.system.SystemErrRule.Disabling the logging in this property file will the make the tests fail of course.
The binary distribution ships with also withslf4j-simple as the logger implementation.The default configuration is provided inpmd-dist/src/main/resources/config/simplelogger.properties.