Preferences:Templates
Table of contents |
Templates
The most important part of the preferences are the templates. They affect which
logger should be used.
Templates are defined in the "Log4E > Templates" preferences page.
Several predefined templates are available (Log4j, Commons Logging and JDK 1.4 logging).
Options:
- Show
- Edit [Pro version only]
- Duplicate [Pro version only]
- Rename [Pro version only]
- Remove [Pro version only]
- ${delimiter}
- ${delimiter_msg}
- ${enclosing_method}
- ${enclosing_method_arguments}
- ${enclosing_method_only}
- ${enclosing_package}
- ${enclosing_type}
- ${exception}
- ${logger}
- ${message}
- ${message_user}
- ${return_value}
- ${variables}
- Imports
- Logger Type
- Initializer
-
Shows ready-made template definitions. These views are read only.
Modifications are not saved!
-
Opens a template definition for selfdefined templates which can be
edited. The modification will be saved immediately when pressing "OK".
-
One can duplicate a template to adapt it to his own logger.
-
Rename a selfdefined template.
-
Only selfdefined templates are allowed to remove. To confirm the
deletion one must press "OK" or "Apply".
Template Definitions
After pressing "Show" or "Edit" a popup window with the definitions is shown.
Sample Template definition:
${logger}.error("${enclosing_method}${delimiter}${message}${delimiter}${message_user}${delimiter}${variables}${delimiter}${return_value}", ${exception})
Variables
-
The delimiter is defined in Log4E > Format prefence page. It is very important
when using the "Modification" task.
-
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);
-
The given enclosing method WITH arguments. It is expected that the variable is embedded in a String context.
e.g. myMethod(String str = " + str + ")
-
The arguments of the given method (${enclosing_method_only}) . It is
expected that the variable is embedded in a String context.
e.g. String str = " + str
-
The given enclosing method WITHOUT arguments.
e.g. myMethod
-
The given package.
-
The given enclosing class.
-
The given exception in a catch clause.
-
The "logger name" is defined in the Declaration Tab of the Log4E > Imports and Declaration prefence page.
-
The message is defined in Log4E > Positions prefence page.
-
It is a user generated message. It is used by the "Substitute" und "Log this position..." tasks.
-
The given return value of the method. It is replaced only if
Log4E > Positions > Method Exit > Move invocation ... is checked.
-
It decouples ${message} from local vars (generated in "Log this position...")
Declaration Tab
Options:
-
defining logger imports.
example: "org.apache.log4j.Logger"
-
Type of logger. example: "Logger"
-
Invocation of the Logger Factory.
example:
/** * Logger for this class */ private static final Logger ${logger} = Logger.getLogger(${enclosing_type}.class)
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 > 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:
- Start Statement
- End Statement
- Throwing Statement
-
E.g entering("${enclosing_type}", "${enclosing_method}", "${message}")
in JDK 1.4 logging. It will be inserted at start position if Log4E > Positions > Method Start > Use position log statements ...
is checked.
-
E.g exiting("${enclosing_type}", "${enclosing_method}",
"${message}${delimiter}${return_value}") in JDK 1.4 logging. It will be
inserted at end position if Log4E > Positions > Method Exit > Use position log statements ...
is checked.
-
E.g throwing("${enclosing_type}", "${enclosing_method}", ${exception})
in JDK 1.4 logging. It will be inserted at catch position if Log4E > Positions > Catch Block > Use position log statements ...
is checked.
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
-
E.g. isLoggable(Level.FINER)
This statement is only used if specified in the Log4E > Statements preference page.
-
E.g. isLoggable(Level.FINER)
This statement is only used if specified in the Log4E > Statements preference page.
-
E.g. isLoggable(Level.FINER)
This statement is only used if specified in the Log4E > Statements preference page.
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.... }