Logger Modification

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.

Several operations are executed:

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