/pmd-4.2.5/docs/rules/logging-java.html
HTML | 246 lines | 101 code | 145 blank | 0 comment | 0 complexity | 2393b86e87c036a8c8de4a7f2397b52e MD5 | raw file
Possible License(s): BSD-3-Clause
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>PMD - Rule Set: Java Logging Rules</title><style type="text/css" media="all">
- @import url("../style/maven-base.css");
-
- @import url("../style/maven-theme.css");</style><link rel="stylesheet" href="../style/print.css" type="text/css" media="print"></link><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"></meta><meta name="author" content="Tom Copeland"></meta><meta name="email" content="tom@infoether.com"></meta></head><body class="composite"><div id="banner"><a href="http://pmd.sourceforge.net/" id="organizationLogo"><img alt="InfoEther" src="http://sourceforge.net/sflogo.php?group_id=56262&type=5"></img></a><a href="http://pmd.sourceforge.net/" id="projectLogo"><img alt="PMD" src="../images/pmd_logo_small.jpg"></img></a><div class="clear"><hr></hr></div></div><div id="breadcrumbs"><div class="xleft"></div><div class="xright">
-
- <a href="http://pmdapplied.com/" class="externalLink" title="External Link">**** Get the book! ****</a>
-
-
-
- <span class="separator">|</span>
-
-
- <a href="http://sourceforge.net/projects/pmd" class="externalLink" title="External Link">SourceForge.net Project Page</a>
-
-
-
- <span class="separator">|</span>
-
-
- <a href="http://sourceforge.net" class="externalLink" title="External Link">Hosted by SourceForge</a>
- </div><div class="clear"><hr></hr></div></div><div id="leftColumn"><div id="navcolumn"><div id="menuOverview"><h5>Overview</h5><ul><li class="none"><a href="http://sourceforge.net/project/showfiles.php?group_id=56262&package_id=51441&release_id=632850" class="externalLink" title="External Link">Download PMD 4.2.5</a></li><li class="none"><a href="http://sourceforge.net/project/shownotes.php?release_id=632850&group_id=56262" class="externalLink" title="External Link">What's new in PMD 4.2.5</a></li><li class="none"><a href="../news.html">PMD in the news</a></li><li class="none"><a href="../products.html">PMD-related products and books</a></li><li class="none"><a href="../bestpractices.html">Best practices</a></li><li class="none"><a href="../future.html">Future directions</a></li><li class="none"><a href="../similar-projects.html">Similar projects</a></li><li class="none"><a href="../credits.html">Credits</a></li><li class="none"><a href="../license.html">License</a></li><li class="none"><a href="../meaning.html">What does 'PMD' mean?</a></li></ul></div><div id="menuUsage"><h5>Usage</h5><ul><li class="none"><a href="../installing.html">Installation</a></li><li class="none"><a href="../running.html">Command line usage</a></li><li class="none"><a href="../ant-task.html">Ant task usage</a></li><li class="none"><a href="../maven-plugin.html">Maven plugin usage</a></li><li class="none"><a href="../mvn-plugin.html">Mvn plugin usage</a></li><li class="none"><a href="../integrations.html">IDE plugin usage</a></li><li class="none"><a href="../suppressing.html">Suppressing warnings</a></li><li class="none"><a href="../cpd.html">Finding duplicated code</a></li><li class="none"><a href="../jspsupport.html">JSP support</a></li></ul></div><div id="menuCustomizing_PMD"><h5>Customizing PMD</h5><ul><li class="none"><a href="../compiling.html">Compiling PMD</a></li><li class="none"><a href="../howtowritearule.html">How to write a rule</a></li><li class="none"><a href="../xpathruletutorial.html">Writing XPath rules</a></li><li class="none"><a href="../howtomakearuleset.html">How to make a rule set</a></li><li class="none"><a href="../howitworks.html">How it works</a></li><li class="none"><a href="../rule-guidelines.html">Rule guidelines</a></li></ul></div><div id="menuFor_example"><h5>For example</h5><ul><li class="none"><a href="../scoreboard.html">Run PMD on a Sourceforge project</a></li></ul></div><div id="menuRule_Sets"><h5>Rule Sets</h5><ul><li class="none"><a href="../rules/index.html">Index</a></li><li class="none"><a href="../rules/android.html">Android</a></li><li class="none"><a href="../rules/basic.html">Basic</a></li><li class="none"><a href="../rules/braces.html">Braces</a></li><li class="none"><a href="../rules/codesize.html">Code Size</a></li><li class="none"><a href="../rules/clone.html">Clone</a></li><li class="none"><a href="../rules/controversial.html">Controversial</a></li><li class="none"><a href="../rules/coupling.html">Coupling</a></li><li class="none"><a href="../rules/design.html">Design</a></li><li class="none"><a href="../rules/finalizers.html">Finalizers</a></li><li class="none"><a href="../rules/imports.html">Import Statements</a></li><li class="none"><a href="../rules/j2ee.html">J2EE</a></li><li class="none"><a href="../rules/javabeans.html">Javabeans</a></li><li class="none"><a href="../rules/junit.html">JUnit Tests</a></li><li class="none"><strong><a href="../rules/logging-java.html">Logging (Java)</a></strong></li><li class="none"><a href="../rules/logging-jakarta-commons.html">Logging (Jakarta)</a></li><li class="none"><a href="../rules/migrating.html">Migrating</a></li><li class="none"><a href="../rules/naming.html">Naming</a></li><li class="none"><a href="../rules/optimizations.html">Optimizations</a></li><li class="none"><a href="../rules/strictexception.html">Strict Exceptions</a></li><li class="none"><a href="../rules/strings.html">Strings</a></li><li class="none"><a href="../rules/sunsecure.html">Sun Security</a></li><li class="none"><a href="../rules/unusedcode.html">Unused Code</a></li><li class="none"><a href="../rules/basic-jsp.html">Java Server Pages</a></li><li class="none"><a href="../rules/basic-jsf.html">Java Server Faces</a></li></ul></div><div id="menuProject_Documentation"><h5>Project Documentation</h5><ul><li class="none"><a href="../index.html">About</a></li><li class="collapsed"><a href="../project-info.html">Project Info</a></li><li class="collapsed"><a href="../maven-reports.html">Project Reports</a></li><li class="none"><a href="../development-process.html">Development Process</a></li></ul></div><div id="legend"><h5>Legend</h5><ul><li class="externalLink">External Link</li><li class="newWindow">Opens in a new window</li></ul></div><a href="http://maven.apache.org/" title="Built by Maven" id="poweredBy"><img alt="Built by Maven" src="../images/logos/mavenlogo_builtby_w.png"></img></a></div></div><div id="bodyColumn"><div class="contentBox"><div class="section"><a name="Java_Logging_Rules"></a><h2>Java Logging Rules</h2>
-
-
- The Java Logging ruleset contains a collection of rules that find questionable usages of the logger.
-
-
-
- <div class="subsection"><a name="MoreThanOneLogger"></a><h3>MoreThanOneLogger</h3>
- <p>Since: PMD 2.0</p>
- <p>
- Normally only one logger is used in each class.
- </p>
-
-
-
-
-
-
-
- <p>This rule is defined by the following Java class:
- <a href="../xref/net/sourceforge/pmd/rules/MoreThanOneLogger.html">net.sourceforge.pmd.rules.MoreThanOneLogger</a>
- </p>
-
-
-
-
-
- <p>Example:</p>
-
- <div class="source"><pre>
-
-
- 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());
- }
-
- </pre></div>
-
-
-
-
-
-
- </div>
-
-
- <div class="subsection"><a name="LoggerIsNotStaticFinal"></a><h3>LoggerIsNotStaticFinal</h3>
- <p>Since: PMD 2.0</p>
- <p>
- In most cases, the Logger can be declared static and final.
- </p>
-
-
-
- <p>This rule is defined by the following XPath expression:</p>
-
-
- <div class="source"><pre>
-
- //VariableDeclarator
- [parent::FieldDeclaration]
- [../Type/ReferenceType
- /ClassOrInterfaceType[@Image='Logger']
- and
- (..[@Final='false'] or ..[@Static = 'false'] ) ]
-
- </pre></div>
-
-
-
-
-
-
-
- <p>Example:</p>
-
- <div class="source"><pre>
-
-
- 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());
- }
-
- </pre></div>
-
-
-
-
-
-
- </div>
-
-
-
- <div class="subsection"><a name="SystemPrintln"></a><h3>SystemPrintln</h3>
- <p>Since: PMD 2.1</p>
- <p>
- System.(out|err).print is used, consider using a logger.
- </p>
-
-
-
- <p>This rule is defined by the following XPath expression:</p>
-
-
- <div class="source"><pre>
-
- //Name[
- starts-with(@Image, 'System.out.print')
- or
- starts-with(@Image, 'System.err.print')
- ]
-
- </pre></div>
-
-
-
-
-
-
-
- <p>Example:</p>
-
- <div class="source"><pre>
-
-
- class Foo{
- Logger log = Logger.getLogger(Foo.class.getName());
- public void testA () {
- System.out.println("Entering test");
- // Better use this
- log.fine("Entering test");
- }
- }
-
- </pre></div>
-
-
-
-
-
-
- </div>
-
-
- <div class="subsection"><a name="AvoidPrintStackTrace"></a><h3>AvoidPrintStackTrace</h3>
- <p>Since: PMD 3.2</p>
- <p>
- Avoid printStackTrace(); use a logger call instead.
- </p>
-
-
-
- <p>This rule is defined by the following XPath expression:</p>
-
-
- <div class="source"><pre>
- //PrimaryExpression
- [PrimaryPrefix/Name[contains(@Image,'printStackTrace')]]
- [PrimarySuffix[not(boolean(Arguments/ArgumentList/Expression))]]
- </pre></div>
-
-
-
-
-
-
-
- <p>Example:</p>
-
- <div class="source"><pre>
-
- class Foo {
- void bar() {
- try {
- // do something
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- </pre></div>
-
-
-
-
-
-
- </div>
-
- </div></div></div><div class="clear"><hr></hr></div><div id="footer"><div class="xright"> 2002-2009, InfoEther</div><div class="clear"><hr></hr></div></div></body></html>