Log4E Preferences

The Plugin is high configurable. You can configure almost everything to adapt your logger to your needs.

It is highly recommended to check the preferences before using the Plugin the first time.

The most important part of the preferences are the templates. They affect which logger should be used.
Templates are defined in the "Log4E > Profile > Templates" preferences page. Several predefined templates are available (Log4j, Commons Logging and JDK 1.4 logging).

Overview

Format

Options:

  • Delimiter
    • e.g. " - ". It separates the different parts of the logger message, e.g. "myMethod() - my message - return value = a"
      The delimiter is important when performing "Modification"!
      The delimiter is used in the templates section ("Log4E > Profile > Templates")
  • Delimiter within message
    • e.g. " : ". It separates the different parts within a ${message} and is used when invoking "Insert Log Statements At This Position..." e.g.
      logger.debug("myMethod() - my message : int i = " + i);
      It should be different to the Delimiter above
      The delimiter is used in the templates section ("Log4E > Profile > Templates")
  • Return value description
    • e.g. "return value = ". It is used when logger message includes the return value of the enclosing method.
  • Open parenthis after methodname
    • You can leave that preference alone. "(" should be the right setting.
      Example:
      logger.debug("myMethod(String) - start");
  • Close parenthis after methodname
    • You can leave that preference alone. ")" should be the right setting.
      Example:
      logger.debug("myMethod(String) - start");

Imports and Declaration

Imports Tab

Options:

  • Import classes when performing "Insert" or "Replace"
    • performs automatic import.
  • Import classes when performing "Declare Logger"

Declaration Tab

Options:

  • Declare Logger when performing "Insert" or "Replace"
    • performs automatic declaration of your logger.
  • Declare Logger when performing "Declare Logger"
    • Logger with static methods don't need a declaration.
  • Create Comment
    • Defining comment for logger declaration. example: "Logger for this class"
  • Access Modifier
    • Modifier for logger declaration. Possible values: "public", "protected", "private", "<none>" (package access only)
  • Define As Static
    • Static modifier in logger declaration.
  • Define As Final
    • Final modifier in logger declaration.
  • Logger Name
    • Name of logger. example: "logger"

As a result the logger imports and declaration is automatically inserted like in that example:

import org.apache.log4j.Logger;

public class MyClass {
	/**
	 * Log4J Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(MyClass.class);

Positions

Log4E inserts logger statements at certain method entries. You can specify the behaviour for each entry differently. The entries are separated in different tabs.

Tab Method Start

It defines the very beginning of the method. The logger statement is inserted there. If method is a constructor and does a constructor invocation (i.e. this(), super()) the logger statement is inserted right behind the invocation.

Options:

  • Disable logging for this position
    • If checked logger statements are not inserted at the beginning of method.
  • Disable in Constructor
    • If Log4E is invoked for the whole class, it leaves out constructor methods
  • Use position log statements instead of level statements
  • Choose level
    • Defines the level of logger. The recommended level for this position is DEBUG.
  • Insert info about current method
    • if disabled, current method infos are not provided
  • Log with parameter types of method
    • Argument types of method
      Example:
      logger.debug("myMethod(String) - start");
  • Log with parameter values of method
    • Argument values of method
      Example:
      logger.debug("myMethod(arg1 = " + arg1 + ") - start");
  • Logger message
    • Your message after method name
      Example:
      logger.debug("myMethod(String) - start");

As a result the logger statements are automatically inserted like in that example:

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

Tab Method Exit

It defines the exit point of a method. That could be a return statement or a the end of the method.
Therfore a logger statement is inserted before every return statement and the end of method.

The settings are the same as at start position except one:

Options:

  • Move invocation in return statement in front of logger
  • Include return value
    • Inserts the return value in logger statement

Example:

Before:

public String myMethod(String arg1) {
	//Your code....
	
	return toString();
}

After:

public String myMethod(String arg1) {
	//Your code....
	
	String returnString = toString();
	logger.debug("myMethod() - end - return value = " + returnString);
	return returnString;
}

Tab Catch Block

It defines the position in a try - catch block. Normally a logger with ERROR level is inserted here providing the given exception.

The settings are the same as at start position.

Tab Other

It defines all other positions than "Method Start", "Method Exit" or "Catch Block".
This occurs when System out's are replaced at other positions or when log statements are modified at other positions or if you use the "Insert Log Statement At This Position..." task.

The settings are reduced to the needed information.

Statements

Options:

  • Embed isTraceEnabled() Statement
    • If checked isTraceEnabled() surrounds the trace statement.

The statements themselves are defined in "Log4E > Profiles > Templates > Is<Level>Enabled Statements" and "Log4E > Profiles > Templates > Is<Position>Enabled Statements"

As a result the logger statements are automatically inserted like in that example:

	public String myMethod(String arg1) {
		if (logger.isDebugEnabled()) {
			logger.debug(...);
		}
		
		//Your code....
	}

Templates

The most important part of the preferences are the templates. They affect which logger should be used.
Templates are defined in the "Log4E > Profile > Templates" preferences page. Several predefined templates are available (Log4j, Commons Logging and JDK 1.4 logging).

Options:

  • Show
    • Shows ready-made template definitions. These views are read only. Modifications are not saved!
  • Edit
    • Opens a template definition for selfdefined templates which can be edited. The modification will be saved immediately when pressing "OK".
  • Duplicate
    • One can duplicate a template to adapt it to his own logger.
  • Remove
    • Only selfdefined templates are allowed to remove. To confirm the deletion one must press "OK" or "Apply".

Template Definitions

After presssing "Show" or "Edit" a popup window with the definitions is shown.

Variables

  • ${delimiter}
    • The delimiter is defined in "Log4E > Format" prefence page. It is very important when using the "Modification" task. The default is " - ".
  • ${delimiter_msg}
    • The delimiter_msg is defined in "Log4E > Format" prefence page. It is used when invoking "Insert Log Statements At This Position..." to separate the informations within a message (the message itself and the variables of the enclosing method). The default is " : ". It should be different to ${delimiter}
      Example:
      logger.debug("myMethod() - my message : int i = " + i);
  • ${enclosing_method}
    • The given enclosing method WITH arguments. e.g. myMethod(String str = " + str + ")
  • ${enclosing_method_arguments}
    • e.g. String str = " + str
  • ${enclosing_method_only}
    • The given enclosing method WITHOUT arguments. e.g. myMethod
  • ${enclosing_package}
    • The given package.
  • ${enclosing_type}
    • The given enclosing class.
  • ${exception}
    • The given exception in a catch clause.
  • ${message}
  • ${return_value}

Declaration Tab

Options:

  • Imports
    • defining logger imports. example: "org.apache.log4j.Logger"
  • Logger Type
    • Type of logger. example: "Logger"
  • Initializer
    • Invocation of the Logger Factory. example: "Logger.getLogger(${enclosing_type})"
      If this field is left blank, the logger will be declared without initialising it. That could be done in the constructor for instance.

As a result the logger imports and declaration is automatically inserted like in that example:

import org.apache.log4j.Logger;

public class MyClass {
	
	Logger logger = Logger.getLogger(MyClass.class);

Level Statements Tab

You can specify level statements for any of these levels:
FINEST, TRACE, DEBUG, INFO, WARN, ERROR, FATAL.
The denotation of the levels is a mixture between Commons Logging and JDK 1.4 logging denotation. FINEST is the lowest level and is only used in JDK 1.4 logging. FATAL is the highest level and is equivalent to SEVERE in JDK 1.4 logging.

Note that these level and methods are not available for all loggers (e.g. Log4j doesn't support TRACE, but the Apache Commons Logger does).

Options:

  • trace() Statement
    • the method which should be invoked if level is TRACE.
      example: trace("${enclosing_method}${delimiter}${message}${delimiter}${return_value}")

As a result the logger statements are automatically inserted like in that example:

	public String myMethod(String arg1) {
		logger.debug("myMethod() - start");
		
		//Your code....
		
		logger.debug("myMethod() - start - return value = myString");
		return "myString";
	}

Is<Level>Enabled Statements Tab

Define the methods which check the level before executing the log statement here.
These statements are only used if specified in the "Log4E > Profile > Statements" preference page.

Options:

  • isTraceEnabled() Statement
    • the method which checks the if logger level is TRACE.
      example: isTraceEnabled() or isLoggable(Level.FINER)

As a result the logger statements are automatically inserted like in that example:

	public String myMethod(String arg1) {
		if (logger.isDebugEnabled()) {
			logger.debug(...);
		}
		
		//Your code....
	}

Position Statements Tab

"Position Statements" is an alternative to the level statements described above. They are introduced in JDK 1.4 logging and are special statements for particular method entries:

Options:

As a result the logger statements are automatically inserted like in that example:

	public String myMethod(String arg1) {
		logger.entering("MyClass", "myMethod()", "start");
		
		//Your code....
		
		logger.entering("MyClass", "myMethod()", "end - return value = myString");
		return "myString";
	}

Is<Position>Enabled Statements Tab

These statements are equivalent to the Is<Level>Enabled Statements described above.

Options:

  • isStartEnabled Statement
  • isEndEnabled Statement
  • isThrowingEnabled Statement

As a result the logger statements are automatically inserted like in that example:

	public String myMethod(String arg1) {
		if isLoggable(Level.FINER) {
			logger.entering(...);
		}
		
		//Your code....
	}

Replacement

Log4E replaces System.out.println, System.out.print, System.err.println, System.err.print and e.printStackTrace statements.
In the Preferences you can choose which logger level should be used.

Options:

  • Replace System.out
    • If unchecked, the replacement of System.out's will be omitted.
  • Replace System.out with logger level
    • Choose the level of logger.
  • Replace System.err
    • If unchecked, the replacement of System.err's will be omitted.
  • Replace System.err with logger level
    • Choose the level of logger.
  • Replace e.printStackTrace()
    • If unchecked, the replacement of e.printStackTrace()'s will be omitted.
  • Replace e.printStackTrace() with logger level
    • This setting is the same as Catch Block settings and is not configurable here.

User Interaction

Options:

  • Enable success message
    • Default: false
  • Enable Preview for inserts on method level
    • Default: false
  • Enable Preview for inserts on class level
    • Default: true
  • Enable Preview for replacement on method level
    • Default: false
  • Enable Preview for replacement on class level
    • Default: true
  • Enable Preview for modifcation on method level
    • Default: true
  • Enable Preview for modifcation on class level
    • Default: true


http://log4e.jayefem.de