当前位置: 首页 > 面试题库 >

jboss不使用logback进行日志记录

单于奇略
2023-03-14
问题内容

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

我正在使用JBoss 6.2,将EAR部署到standalone /
deployments目录并启动服务器(除了我得到这个异常的事实,这一切都很好,很高兴java.lang.ClassCastException: org.slf4j.impl.Slf4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext),但是无论如何,回到了主要问题。

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

 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文件中

这是我的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进行排除;

<?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。 ejb的ejbmodule文件夹与耳朵包装在一起(是否使其成为子部署??)

我不确定自己缺少什么,希望有人能帮忙


问题答案:

已修复-该项目仅部署一个EAR文件,该文件旁边打包了2个ejb jar。我的最初尝试涉及制作具有以下格式的jboss-deployment-
structure.xml:

<?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>

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

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

这是最新的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 /中找到



 类似资料:
  • 我在具有以下logback.xml文件的类路径中有slf4j和logback jar(该文件以前已经成功使用过)。但是,DOCX4J3.0仍然将日志记录信息打印到标准输出。我正在使用NetBeans7.4构建基于docx4j的应用程序。我想将日志级别更改为错误,并将其发送到日志文件中。不知道我错过了什么。任何帮助都是非常感谢的。

  • 因此,我正在部署一个使用Hibernate4.3.6的web应用程序。和Tomcat 7。我正在尝试使用SLF4J作为日志抽象层来日志。但是,我有很多问题和疑问。首先,Hibernate和Tomcat都有不同的日志框架,分别是jboss-logging和juli(即使我在库中找不到juli),所以我认为我必须安装从这些框架到SLF4J的桥梁。对于Hibernate,根据这个答案,一个解决方案可以是

  • Web-INF中的jboss-deployment-structure.xml: 和log4j.xml设置(在war中位于“web-inf/classes/log4j.xml”中):

  • 我正在尝试使用PostSharp和multicastAttribute实现日志记录。使用PostSharp诊断库中的日志功能。 我有一个GlboalAspects。启动项目目录中的cs。内容如下。 右键单击我的项目并选择属性,默认命名空间是“alp_generator” 我不知道“PostSharp.Patterns.Diagnostics.LogAttribute”是否正确。 我根本没有日志记录

  • 问题内容: 我正在使用的Web应用程序偶尔会为某些用户带来数据完整性问题。我想打开跟踪级别的日志记录,但是由于我们每秒要处理100个请求,因此每个日志记录都是不可能的。 log4j是否可以有条件地记录日志?换句话说,我希望仅在特定用户发出请求时才能获得跟踪日志。由于我事先不知道哪些用户会受到影响,因此我无法简单地临时对用户名进行硬编码。 编辑: 我想我需要更清楚一点。我可以轻松地在日志语句中添加条