Movatterモバイル変換


[0]ホーム

URL:


 
» Logging Edit on GitHub

Logging

Table of Contents

Logging API is slf4j

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);

In Unit Tests

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=debug

If 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.

Binary distribution

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.

Tags:devdocs

This documentation is written in markdown.
If there is something missing or can be improved, edit this page on github and create a PR: Edit on GitHub

©2026 PMD Open Source Project. All rights reserved.
Site last generated: Jan 30, 2026

PMD                logo


[8]ページ先頭

©2009-2026 Movatter.jp