Log4e是一个免费的Eclipse Plugin,它可帮助你在你的Java工程中快速加入Log;Log4E不依赖任何Log框架,可以通过配置支持Log4j, Commons Logging, 以及JDK 1.4 logging等。我们可以在http://log4e.jayefem.de/index.php/Download网站上下载Log4e最新版本。下载后将相应文件夹拷贝到Eclipse的插件目录下,重新Eclipse,在首选项中会多出一个Log4e选项。
Log4e可以有多个插入Log为一个方法、类,当然也可以在当前位置插入Log,同时其也可以把Sysout.out.println()的转换为log;所有的这一切只需要你点点鼠标或者按一次快捷键,下面我们只以为一个方法插入Log为例来讲解
启动eclipse,进行注册,选择window — preferences — log4e输入:
test
test
test
e538-c851-cf5a-930c-1943
在log4e > position 选项中
Options:
- Skip logging for this position
如果选中,log语句将不会插入method的最开始位置(即 不会显示 log.debug(xxx——start)这个信息) - Skip in Constructor
选中后,log语句不会插入构造方法 - Skip methods with empty body [Pro version on
ly]
log语句不插入内容为空的method中 - Skip getter [Pro version on
ly]
选中后,log语句不插入getter方法中,注意,log4e会将所有类似如下形式的方法都等同为getter方法
public String anyMethodName() { return "mystring"; }
- Skip setter [Pro version on
ly]
参照 Skip getter 的说明
public void anyMethodName(String mystring) { this.mystring = mystring; }
- Use position log statements instead of level statements
选择一个在 Log4E > Templates > Position Statements中定义的positon statements - Choose level
选择一个log级别,默认为debug - Insert info about current method
显示当前方法的信息,如果禁用就不显示。(会影响下面的选项,具体作用还没有试) - Log with parameter types of method
Argument types of method
Example:logger.debug("myMethod(String) - start");
- Log with parameter names of method
Argument names of method
Example:logger.debug("myMethod(arg1) - start");
- Log with parameter values of method
Argument values of method
Example:logger.debug("myMethod(" + 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 co
de.... }
Tab Catch Block
在catch中的log会自动将给定的exception作为参数并使用error级别显示
The settings are the same as at start position. Some additional options are available:
- Skip empty catch block [Pro version on
ly]
不在空的catch中显示log语句。 If checked, logger statements are not inserted in empty catch blocks. If unchecked, the options "Level for empty catch block" and "Message in empty catch block (${message})" will be used instead. - Level for empty catch block [Pro version on
ly]
为空的catch中的log语句选择一个指定级别。 Choose a level that should be used in empty catch blocks. This can be different from "Choose level". Default: "Log4j Warn/JDK14 Warning" - Message in empty catch block (${message}) [Pro version on
ly]
Choose a message that should be used in empty catch blocks. This can be different from "Logger message". Default: "exception ignored" - Log all variables available [Pro version on
ly]
If checked all variables available in the scope of the current catch block will be logged.