##### Overview

- Download PMD 4.2.5
- What's new in PMD 4.2.5
- PMD in the news
- PMD-related products and books
- Best practices
- Future directions
- Similar projects
- Credits
- License
- What does 'PMD' mean?

##### Usage

- Installation
- Command line usage
- Ant task usage
- Maven plugin usage
- Mvn plugin usage
- IDE plugin usage
- Suppressing warnings
- Finding duplicated code
- JSP support

##### Customizing PMD

- Compiling PMD
- How to write a rule
- Writing XPath rules
- How to make a rule set
- How it works
- Rule guidelines

##### For example

- Run PMD on a Sourceforge project

##### Rule Sets

- Index
- Android
- Basic
- Braces
- Code Size
- Clone
- Controversial
- Coupling
- Design
- Finalizers
- Import Statements
- J2EE
- Javabeans
- JUnit Tests
- Logging (Java)
- Logging (Jakarta)
- Migrating
- Naming
- Optimizations
- Strict Exceptions
- Strings
- Sun Security
- Unused Code
- Java Server Pages
- Java Server Faces

##### Project Documentation

- About
- Project Info
- Project Reports
- Development Process

##### Legend

- External Link
- Opens in a new window

## Java Logging Rules

The Java Logging ruleset contains a collection of rules that find questionable usages of the logger.

### MoreThanOneLogger

Since: PMD 2.0

Normally only one logger is used in each class.

This rule is defined by the following Java class: net.sourceforge.pmd.rules.MoreThanOneLogger

Example:

    class Foo{
        Logger log = Logger.getLogger(Foo.class.getName());
        // It is very rare to see two loggers on a class, normally
        // log information is multiplexed by levels
        Logger log2= Logger.getLogger(Foo.class.getName());
    }

### LoggerIsNotStaticFinal

Since: PMD 2.0

In most cases, the Logger can be declared static and final.

This rule is defined by the following XPath expression:

    //VariableDeclarator
     [parent::FieldDeclaration]
     [../Type/ReferenceType
      /ClassOrInterfaceType[@Image='Logger']
       and
      (..[@Final='false'] or ..[@Static = 'false'] ) ]

Example:

    class Foo{
        Logger log = Logger.getLogger(Foo.class.getName());
        // It is much better to declare the logger as follows
        // static final Logger log = Logger.getLogger(Foo.class.getName());
    }

### SystemPrintln

Since: PMD 2.1

System.(out|err).print is used, consider using a logger.

This rule is defined by the following XPath expression:

    //Name[
        starts-with(@Image, 'System.out.print')
        or
        starts-with(@Image, 'System.err.print')
        ]

Example:

    class Foo{
        Logger log = Logger.getLogger(Foo.class.getName());
        public void testA () {
            System.out.println("Entering test");
            // Better use this
            log.fine("Entering test");
        }
    }

### AvoidPrintStackTrace

Since: PMD 3.2

Avoid printStackTrace(); use a logger call instead.

This rule is defined by the following XPath expression:

    //PrimaryExpression
     [PrimaryPrefix/Name[contains(@Image,'printStackTrace')]]
     [PrimarySuffix[not(boolean(Arguments/ArgumentList/Expression))]]

Example:

    class Foo {
     void bar() {
      try {
       // do something
      } catch (Exception e) {
       e.printStackTrace();
      }
     }
    }