jboss 不使用 logback 进行日志记录 [英] jboss not using logback for logging

查看:33
本文介绍了jboss 不使用 logback 进行日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个曾经使用 log4j 的应用程序迁移到 logback/slf4j 并且现在已经出现了大约 2 周的问题......我做了一个小项目来测试 logback/slf4j 并且效果很好,但出于某种原因将其应用于实际应用程序时,它只是不想工作.

I'm migrating an application that used to use log4j to logback/slf4j and have been having issues for about 2 weeks now... I made a small project to test logback/slf4j and that worked great, but for some reason when applying it to the actual app it just doesnt want to work.

我正在使用 JBoss 6.2 并将一个 EAR 部署到 standalone/deployments 目录并启动服务器(这一切都很好而且很开心,除了我收到这个异常 java.lang.ClassCastException: org.slf4j.impl.Slf4jLoggerFactory 不能转换为 ch.qos.logback.classic.LoggerContext) 但无论如何,回到主要问题.

I'm using JBoss 6.2 and deploying an EAR to the standalone/deployments directory and starting the server (which is all good and happy, except for the fact that I'm getting this exception java.lang.ClassCastException: org.slf4j.impl.Slf4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext) but anyway, back to the main problem.

当我运行应用程序时,我将其打印到我指定的日志文件中

when I run the application I get this printed to the log file I specified

 10:51:06.752 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider
10:51:06.780 [main] DEBUG o.j.n.r.client.InitialContextFactory - Looking for jboss-naming-client.properties using classloader sun.misc.Launcher$AppClassLoader@194d4313
10:51:06.782 [main] DEBUG o.j.n.r.client.InitialContextFactory - jboss.naming.client.endpoint.create.options. has the following options {}
10:51:06.783 [main] DEBUG o.j.n.r.client.InitialContextFactory - jboss.naming.client.remote.connectionprovider.create.options. has the following options {}
10:51:06.789 [main] INFO  org.xnio - XNIO Version 3.0.7.GA-redhat-1
10:51:06.798 [main] INFO  org.xnio.nio - XNIO NIO Implementation Version 3.0.7.GA-redhat-1
10:51:06.815 [main] INFO  org.jboss.remoting - JBoss Remoting version 3.2.18.GA-redhat-1
10:51:06.856 [Remoting "config-based-naming-client-endpoint" read-1] DEBUG org.xnio.nio - Started channel thread 'Remoting "config-based-naming-client-endpoint" read-1', selector sun.nio.ch.WindowsSelectorImpl@2668d102
10:51:06.856 [Remoting "config-based-naming-client-endpoint" write-1] DEBUG org.xnio.nio - Started channel thread 'Remoting "config-based-naming-client-endpoint" write-1', selector sun.nio.ch.WindowsSelectorImpl@2b71ee01
10:51:06.915 [main] DEBUG o.j.n.r.client.InitialContextFactory - jboss.naming.client.connect.options. has the following options {}
10:51:07.393 [main] DEBUG org.hornetq.core.client - Trying reconnection attempt 0/1
10:51:07.401 [main] DEBUG org.hornetq.core.client - Trying to connect with connector = org.hornetq.core.remoting.impl.netty.NettyConnectorFactory@b2e86ae, parameters = {port=5445, host=localhost} connector = NettyConnector [host=localhost, port=5445, httpEnabled=false, useServlet=false, servletPath=/messaging/HornetQServlet, sslEnabled=false, useNio=false]
10:51:07.425 [main] DEBUG org.hornetq.core.client - Started Netty Connector version 3.6.6.Final-redhat-1-fd3c6b7
10:51:07.425 [main] DEBUG org.hornetq.core.client - Trying to connect at the main server using connector :TransportConfiguration(name=netty, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?port=5445&host=localhost
10:51:07.426 [main] DEBUG org.hornetq.core.client - Remote destination: localhost/127.0.0.1:5445
10:51:07.481 [main] DEBUG org.hornetq.core.client - Reconnection successfull
10:51:07.494 [Thread-1 (HornetQ-client-global-threads-272238939)] DEBUG org.hornetq.utils - using dummy address ffffffe9:6c:ffffff84:ffffffb0:2e:-127
10:51:07.496 [main] DEBUG org.hornetq.core.client - ClientSessionFactoryImpl received backup update for live/backup pair = TransportConfiguration(name=netty, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?port=5445&host=localhost / null but it didn't belong to TransportConfiguration(name=netty, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?port=5445&host=localhost
10:51:07.779 [Remoting "config-based-naming-client-endpoint" task-3] ERROR o.j.n.r.p.v1.RemoteNamingStoreV1 - Channel end notification received, closing channel Channel ID c0d4d8c1 (outbound) of Remoting connection 6fb0b6e3 to localhost/127.0.0.1:4447

但是!!!这是打印到我的日志文件的所有内容,其余的 log.info/log.warn 等...都打印到 standalone/log/server.log 文件

HOWEVER!!! this is all that is printed to my log file, the rest of the log.info/log.warn etc... are all printed to the standalone/log/server.log file

这是我的 logback.xml

here is my logback.xml

     <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true">
        <appender
            name="ConsoleAppender"
            class="ch.qos.logback.core.ConsoleAppender">


        <encoder>
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
        </encoder>
    </appender>

  <!-- Rollover at midnight each day  -->
    <appender
        name="LOG_AUDIT"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--  <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler" /> -->

        <file>${my.logPath}/Logs/MYLOG.log</file>
        <append>true</append>
        <datePattern>'.'yyyy-MM-dd</datePattern>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>logFile.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>

        <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <!--<encoder>
            <pattern>&lt;%5p ${obphm.version}&gt; [%d{ISO8601}] %t %c - %m%n</pattern>
        </encoder>-->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender
        name="ERROR_AUDIT"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--  <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler" /> -->
        <file>${my.logPath}/Logs/MYERRORS.log</file>
        <append>true</append>
        <datePattern>'.'yyyy-MM-dd</datePattern>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>logFile.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>

        <!-- encoders are assigned the type
         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            <!--<pattern>&lt;%5p ${obphm.version}&gt; [%d{ISO8601}] %t %c - %m%n</pattern>-->
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="LOG_AUDIT" />
        <appender-ref ref="ERROR_AUDIT" />
        <appender-ref ref="ConsoleAppender" />
    </root>
</configuration>

而且我还尝试为排除项制作一个 jboss-deployment-structure.xml;

and I also tried to make a jboss-deployment-structure.xml for exclusions;

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
    <deployment>
        <exclusions>
            <module name="org.apache.commons.logging" />
            <module name="org.slf4j" />
            <module name="org.slf4j.ext" />
            <module name="org.slf4j.jcl-over-slf4j" />

            <module name="org.slf4j.impl" />
            <module name="org.apache.log4j" />
        </exclusions>
        <dependencies>

            <module name="ch.qos.logback" />
            <module name="org.slf4j.v175" />
        </dependencies>
    </deployment>

</jboss-deployment-structure>

但这似乎没有做任何事情,出于某种原因它仍在尝试访问 org.slf4j.impl...我有 jboss-deployment-structure 耳朵的 META-INF 文件夹和 logback.xml在 ejb 的一个 ejbmodule 文件夹中,该文件夹与耳朵一起打包(这会使其成为子部署吗??)

but that doesnt seem to be doing anything, it's still trying to access org.slf4j.impl for some reason... I have the jboss-deployment-structure the META-INF folder of the ear, and the logback.xml in one of the ejb's ejbmodule folders which gets packaged with the ear (would that make it a subdeployment??)

我不确定我错过了什么,希望有人能帮忙

I'm not sure what I'm missing, I hope someone can help

推荐答案

Fixed-这个项目只部署了一个 EAR 文件,其中有 2 个 ejb jar.我的第一次尝试涉及制作具有以下格式的 jboss-deployment-structure.xml:

Fixed- this project only deploys an EAR file which has 2 ejb jars packaged alongside it. My first attempts involved making a jboss-deployment-structure.xml which had this format:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
    <deployment>
        <!--Exclusions allow you to prevent the server from automatically adding 
            some dependencies-->
        <exclusions>
            <module name="org.apache.commons.logging" />
            <module name="org.slf4j" />
            <module name="org.slf4j.ext" />
            <module name="org.slf4j.impl" />
            <module name="org.apache.log4j" />
            <module name="org.jboss.logmanager"/> 
            <module name="jcl-over-slf4j"/>
        </exclusions>

        <dependencies>
            <module name="org.slf4j.v175" />
            <module name="ch.qos.logback" /> 

        </dependencies>
        </deployment>
</jboss-deployment-structure>

我尝试了多种排除/依赖项的变体,但似乎没有任何效果.

I tried multiple variations of exclusions/dependencies and nothing seemed to work.

然后我决定为捆绑在耳朵中的每个 ejb jar(来自其他 2 个项目)添加子部署,并为它们添加排除/依赖项,最后它似乎起作用了.但是,这样做之后,服务器找不到logback.xml...可能是因为我在代码中设置了joran configurator,不确定.

I then decided to add subdeployments for each of the ejb jars that are bundled in the ear (from 2 other projects) and added exclusions/dependencies for those, and finally it seemed to work. However, after doing this, the server cant find logback.xml... maybe that's because I've set up joran configurator in the code, not sure.

这里是最新的 jboss-deployment-structure.xml

heres the latest jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment></deployment> <!-- doesnt need anything in here -->
<sub-deployment name="myjar.jar">
        <exclusions>
            <module name="org.apache.commons.logging" /> 
            <module name="org.slf4j" />
            <module name="org.slf4j.ext" />
            <module name="org.slf4j.impl" />
            <module name="org.apache.log4j" /> 
            <module name="org.jboss.logmanager"/> 
            <module name="jcl-over-slf4j"/>
        </exclusions>
        <dependencies>
            <module name="org.slf4j.log4j-over-slf4j"/>
            <module name="org.slf4j.v175" />
            <module name="ch.qos.logback" />

        </dependencies>
    </sub-deployment>
    <sub-deployment name="mysecondjar.jar">
        <exclusions>
            <module name="jcl-over-slf4j"/>
            <module name="org.apache.commons.logging" />
            <module name="org.slf4j" />
            <module name="org.slf4j.ext" />
            <module name="org.slf4j.impl" />
            <module name="org.apache.log4j" /> 
            <module name="org.jboss.logmanager"/> 
        </exclusions>
        <dependencies>
            <module name="org.slf4j.log4j-over-slf4j"/>
            <module name="org.slf4j.v175" />
            <module name="ch.qos.logback" />

        </dependencies>
    </sub-deployment>

</jboss-deployment-structure>

还有...这里的依赖项是使用jboss中的现有模块作为参考定制的.这些可以在您的 jboss_home_install/modules/

also... the dependencies in here are custom made using the existing modules in jboss as a reference. Those could be find in your jboss_home_install/modules/

这篇关于jboss 不使用 logback 进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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