Visitors Counter

1594675
Removal of the current logger statements [pro version only] PDF Print

Overview

The actions "Remove logger in this method" and "Remove logger of this class" automatically remove all logger statements in the method or class. On class scope the logger declaration and imports are removed, too. See also the screenshots.

Log4E needs to know which logger framework is used because it removes all statements defined in the logger framwork templates (Preferences:Templates).

See the screenshots for a quick overview.

Example:

Before:

import org.apache.log4j.Logger;
public class MyClass {
/**
* Logger for this class
*/
private static final Logger logger =
Logger.getLogger(MyClass.class);

public String myMethod() {
if (logger.isDebugEnabled()) {
logger.debug("myMethod() - start");
}
		//Your code... 
		try {

} catch (Exception e) {
logger.error("myMethod()", e);

//Your code...

if (logger.isDebugEnabled()) {
logger.
debug("myMethod() - othertext");
}

if (logger.isDebugEnabled()) {
logger.debug("myMethod() - end");
}
return "text";
}

String returnString = toString();
if (logger.isDebugEnabled()) {
logger.debug("myMethod() - end");
}
return returnString;
}
}
 

After:

public class MyClass {
public String myMethod() {
 		//Your code... 		
		try {

} catch (Exception e) {
//Your code...

return "text";
}

String returnString = toString();
return returnString;
}
}

 

A special case is when your code is woven into a is<Level>Enabled() statement. In that case Log4E pops up a warning that not all code can be removed. Only the logger statements without any user code can be removed.

Example:

Before:

import org.apache.log4j.Logger;
public class MyClass {
/**
* Logger for this class
*/
private static final Logger logger =
Logger.getLogger(MyClass.class);

public void myMethod() {
if (logger.isDebugEnabled()) {
logger.debug("myMethod() - start");
			// user code
System.out.println("");
}
}
}

After: 

import org.apache.log4j.Logger;
public class MyClass {
public void myMethod() {
if (logger.isDebugEnabled()) {
// user code
System.out.println("");
}
}
}