Visitors Counter

1616214
Home arrow User Guide arrow Actions arrow Re-Application
Re-Application PDF Print

Already exisiting loggers can be modified by Log4E.

Note that the modification algorithm changed from v0.5.5 to the current version and that using this task could delete a logger message under certain circumstances! See the Logger Modification:Algorithm section for more information.

See the screenshots for a quick overview. 

Several operations are executed:

  • Surround isLevelEnabled() statements
  • Insert info about current method
  • Move invocation in return statement in front of logger

Example:

Before:

public class ActualClass {
//typical copy/paste mistake
/**
* Logger for this class
*/
private static final Logger logger = Logger.getLogger(Other.class);

public String myMethod(String str, int integer) {
logger.debug("otherMethod() - starttext");
try {

} catch (Exception e) {
logger.error("otherMethod() - errortext", e);

//Your code...

logger.debug("otherMethod() - othertext");

logger.debug("otherMethod() - returntext");
return "text";
}
logger.debug("otherMethod() - endtext");
return toString();
}
}

 

After:

public class ActualClass {
//typical copy/paste mistake
/**
* Logger for this class
*/
private static final Logger logger =
Logger.getLogger(ActualClass.class);

public String myMethod(String str, int integer) {
if (logger.isDebugEnabled()) {
logger.debug(
"myMethod(String str = "
+ str
+ ", int integer = "
+ integer
+ ") - starttext");
}
try {

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

//Your code...

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

if (logger.isDebugEnabled()) {
logger.
debug("myMethod() - returntext - return value = text");
}
return "text";
}

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

Note that Log4E checks if "returnString" already exists and appends a number. e.g. if "returnString" exists the new variable would be "returnString2" (and so on).