Logger Inserts

You can either insert logger statements for the whole class, for a certain method or at a certain position. These tasks are described in the following subsections.

Inserts for method/class

Two operations are executed:

  • insert logger statements at certain method entries. These are: method start, method exit, catch block
  • surround logger with isLevelEnabled()
  • Most of the documentation is already done in the Preferences (see Statements and Positions).

    Here's an example:

    Before:

    public String myMethod(String theString, int theInt) {
    	//Your code....
    	try {
    		doSomethingVeryDangerous();
    	} catch (Exception myexception) {
    		return null;
    	}
    	return toString();
    }
    

    After:

    public String myMethod(String theString, int theInt) {
    	if (logger.isDebugEnabled()) {
    		logger.debug(
    			"myMethod(String theString = "
    				+ theString
    				+ ", int theInt = "
    				+ theInt
    				+ ") - start");
    	}
    
    	//Your code....
    	try {
    		doSomethingVeryDangerous();
    	} catch (Exception myexception) {
    		logger.error("myMethod()", myexception);
    		
    		if (logger.isDebugEnabled()) {
    			logger.debug("myMethod() - end");
    		}
    		return null;
    	}
    
    	String returnString = toString();
    	if (logger.isDebugEnabled()) {
    		logger.debug("myMethod() - end");
    	}
    	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).

    Insert at certain position

    Place the textcursor at a valid position within a method and invoke the submenu "Log4E->Insert Log Statement At This Position...". A Wizard pops up as shown below.

    Wizard settings:

    • Logger message
      • place your own message there
    • Method paramters
      • List of parameters of this method
    • Inlcude paramter type info
      • If checked the given type of the parameter will be logged too
    • Available local variables
      • List of local variables avaible at this position
    • Inlcude variable type info
      • If checked the given type of the variable will be logged too
    • Level
      • logger level
    • Surround with islevelEnabled()
      • This depends on the selected logger level.

    There's a preview afterwards:



    http://log4e.jayefem.de