log4e的配置

Log4e是一个免费的Eclipse Plugin,它可帮助你在你的Java工程中快速加入LogLog4E不依赖任何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 选项中

log4e的配置 - BigTime - BigTime的博客


Options:

  • Skip logging for this position
    如果选中,log语句将不会插入method的最开始位置(即 不会显示 log.debug(xxx——start)这个信息)
  • Skip in Constructor
    选中后,log语句不会插入构造方法
  • Skip methods with empty body [Pro version only]
    log语句不插入内容为空的method中
  • Skip getter [Pro version only]
    选中后,log语句不插入getter方法中,注意,log4e会将所有类似如下形式的方法都等同为getter方法
    public String anyMethodName() {
     return "mystring";
    }
  • Skip setter [Pro version only]
    参照 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 code....
    }

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 only]
    不在空的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 only]
    为空的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 only]
    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 only]
    If checked all variables available in the scope of the current catch block will be logged.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值