log4j只能在我的java-Enterprise应用程序模块ejb-上查看错误级别 [英] log4j only can view error level on my java-Enterprise application-Module ejb- with spring

查看:211
本文介绍了log4j只能在我的java-Enterprise应用程序模块ejb-上查看错误级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netbeans在ejb模块中处理我的java Enterprise应用程序。
当我运行MyClass.java时,我只查看错误级别。



MyEnterpriseApplication-ejb:源包:

I'm working on my java Enterprise application in ejb module with Netbeans.
When I run "MyClass.java" I only view error level.

MyEnterpriseApplication-ejb:Source Packages:

package com.mycompany;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class MyClass {

public static final Logger logger = LogManager.getLogger(MyClass.class);

public static void main(String[] arg) {
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:context.xml");

    logger.info("level info");
    logger.error("level error");
    logger.debug("level debug");
    logger.warn("level warn");
}
}

当我运行这个课程时...

输出:

When I run this class...
Output:

------------------------------------------------------------------------
Building MyEnterpriseApplication-ejb 1.0-SNAPSHOT
------------------------------------------------------------------------

[dependency:copy]

[resources:resources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 1 resource

[compiler:compile]
Compiling 1 source file to Z:\NetBeansProjects\MyEnterpriseApplication\MyEnterpriseApplication-ejb\target\classes

[exec:exec]
20:26:23.885 [main] ERROR com.mycompany.MyClass - level error
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 2.328s
Finished at: Mon May 27 20:26:23 CEST 2013
Final Memory: 14M/162M
------------------------------------------------------------------------

如何添加log4j.xml文件并添加到spring上下文文件?这是方法吗?

How can I add a log4j.xml file and add to spring context file? this is the way?

推荐答案

使用log4j version2.0,您无需调用DomConfigurator。 (我认为它不再存在。)
配置文件应该被称为log4j2.xml,如果它在类路径中,它将被拾取。

With log4j version2.0, you don't need to call DomConfigurator. (I don't think it exists any more.) The config file should be called log4j2.xml and will be picked up if it is in the classpath.

您的maven依赖关系对我来说是正确的。

Your maven dependencies look correct to me.

您的示例MyClass代码看起来也不错。 (尽管您不需要ApplicationContext进行日志记录。)

Your example MyClass code also looks fine. (Although you don't need the ApplicationContext for the logging.)

这篇关于log4j只能在我的java-Enterprise应用程序模块ejb-上查看错误级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆