在JBoss 7.1.1中以DEBUG级别登录 [英] Logging with DEBUG level in JBoss 7.1.1

查看:90
本文介绍了在JBoss 7.1.1中以DEBUG级别登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:我的应用程序应包含错误和调试级别的消息.必须通过JBoss管理控制台设置(切换)日志记录级别.日志应该写入标准的JBoss日志文件和服务器控制台.

Goal: My application should have messages with ERROR and DEBUG levels. Level of logging must set (switch) via JBoss Admin Console. Logging should be written to standard JBoss log file and server console.

我尝试使用java.util.logging.Logger,但是此记录器没有必要的级别. 我用slf4j切换到log4j.存在错误级别为ERROR的消息. DEBUG和System.out.println的问题. 有趣的是,在测试阶段可以看到DEBUG级别.

I tried to use java.util.logging.Logger, but this logger have not necessary levels. I switched to log4j with slf4j. Messages with ERROR level is exist. Problem with DEBUG and System.out.println. Interesting, that DEBUG level is visible in testing phase.

 import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    /**
     * Logger creation and configuration
     */
    public class ResourcesLog {

        @Produces
        Logger getLog(InjectionPoint ip) {
            String category = ip.getMember().getDeclaringClass().getName();
            return LoggerFactory.getLogger(category);
        }
    }

或仅LOG = LoggerFactory.getLogger(MyClass.class); Pom文件:

or just LOG = LoggerFactory.getLogger(MyClass.class); Pom file:

<dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.6</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.6</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.6</version>

        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.6</version>
        </dependency>

也许包含不必要的内容.我无法将slf4j-simple和slf4j-api设置为提供"-出现错误.这个图书馆应该在战争之内吗?

Maybe contains unnecessary. I can't set slf4j-simple and slf4j-api as "provided" - got an error. Should this libs be inside war?

WEb-INF中的jboss-deployment-structure.xml:

jboss-deployment-structure.xml in WEb-INF:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.apache.commons.logging" />
            <module name="org.apache.log4j" />
            <module name="org.jboss.logging" />
            <module name="org.jboss.logging.jul-to-slf4j-stub" />
            <module name="org.jboss.logmanager" />
            <module name="org.jboss.logmanager.log4j" />
            <module name="org.slf4j" />
            <module name="org.slf4j.impl" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

资源文件夹中的log4j.xml设置(战争中位于'WEB-INF/classes/log4j.xml'中):

And log4j.xml settings in resource folder (in war is in 'WEB-INF/classes/log4j.xml'):

<?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
    <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
        <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
        <param name="File" value="${jboss.server.log.dir}/server.log"/>
        <param name="Append" value="true"/>
        <param name="DatePattern" value="'.'yyyy-MM-dd"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
        </layout>
    </appender>
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
        <param name="Target" value="System.out"/>
        <param name="Threshold" value="DEBUG"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
        </layout>
    </appender>
    <category name="org.mypackage">
        <priority value="DEBUG"/>
    </category>
    <root>
        <level value="INFO"/>
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>
</log4j:configuration>

推荐答案

由于您希望日志进入标准日志记录配置,并且希望通过管理选项控制此配置,因此无需使用log4j.放下log4j.xmljboss-deployment-structure.xml.另外,您只需要slf4j-api并且需要将其标记为已提供.

Since you want your logs to go to the standard logging configuration and you want to control this configuration with a management option, there is no need to use log4j. Ditch the log4j.xml and the jboss-deployment-structure.xml. Also you'll only need the slf4j-api and it needs to be marked as provided.

接下来,您需要在服务器上配置记录器.在CLI中,对于独立服务器,它将是如下所示的命令

Next you need to configure a logger on the server. In CLI it would be a command like the following for a standalone server

/subsystem=logging/logger=org.mypackage:add(level=DEBUG)

您还需要设置控制台处理程序和文件处理程序以允许调试消息.默认情况下,文件处理程序已设置为打印调试消息.要更改控制台处理程序以允许调试消息,请执行以下CLI命令.

You'd also need to set the console handler and the file handler to allow for debug messages. By default the file handler is already set to print debug messages. To change the console handler to allow debug messages execute the follow CLI command.

/subsystem=logging/console-handler=CONSOLE:write-attribute(name=level,value=DEBUG)

这些更改也可以在Web控制台中进行.

These changes can also be made in the web console as well.

这篇关于在JBoss 7.1.1中以DEBUG级别登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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