Logback RollingFileAdapter 在 Payara Server 中无法正常工作

Logback RollingFileAdapter does not work as expected in Payara Server

我已经在 Whosebug 上搜索了很多google,但我的问题还没有解决。

问题:

在代码中我有这些记录器:

@Stateless
public class NotificatrionService implements INotificationService {
    private final static Logger logger = LoggerFactory.getLogger("DEF");
    private final static Logger logger_wsdlr = LoggerFactory.getLogger("wsdlr");
:
:
}

在某些情况下我会使用每一个

:
logger_wsdlr.info("Some info messages");
:
logger.debug("Some debug messages"));
:

要使用 Payara Server 4(稳定的 Glassfish 4)设置 logback,请按照 @vzamanillo 在 post:

上写的说明进行操作

cannot get SLF4J working with glassfish 4

人们在该指南(或其他发现的指南)中使用 ch.qos.logback.core.FileAppender。使用此 appender logback 效果很好,但我需要轮换日志文件。然后我就在我的 logback.xml 中设置 ch.qos.logback.core.rolling.RollingFileAppender,就像这样:

<configuration scan="true" debug="true">
    <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
        <resetJUL>true</resetJUL>
    </contextListener>
    <property name="pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level][%thread][%logger{36}]%msg%n"/>
    <property name="dir" value="/tmp/log"/>
    <appender name="DEF" class="ch.qos.logback.core.FileAppender">
        <file>${com.sun.aas.instanceRoot}/logs/my_def.log</file>
        <append>true</append>
        <encoder>
            <Pattern>${pattern}</Pattern>
        </encoder>
    </appender>
    <appender name="WSDLR" class="ch.qos.logback.core.RollingFileAppender">
        <file>${dir}/dt_wsdlr.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${dir}/dt_wsdlr-%d{yyyy.MM.dd}.log</fileNamePattern>
            <maxHistory>90</maxHistory>
            <totalSizeCap>3GB</totalSizeCap>
        </rollingPolicy>

        <encoder>
            <Pattern>${pattern}</Pattern>
        </encoder>
    </appender>
    <!-- appender that replace payara default server.log, defualt was redirected to ${com.sun.aas.instanceRoot}/tmp/server.log -->
    <appender name="GF" class="ch.qos.logback.core.FileAppender">
        <file>${com.sun.aas.instanceRoot}/logs/server.log</file>
        <append>true</append>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>

        <encoder>
            <Pattern>${pattern}</Pattern>
        </encoder>
    </appender>
    <root level="INFO">
        <appender-ref ref="GF"/>
    </root>

    <logger level="TRACE" name="DEF" additivity="false">
        <appender-ref ref="STDOUT"/>
    </logger>
    <logger level="DEBUG" name="wsdlr" additivity="false">
        <appender-ref ref="WSDLR"/>
    </logger>
</configuration>

当我在我的代码中使用 RollingFileAppender 引用时,根本没有创建与附加程序关联的文件并且日志只是丢失


我尝试应用上面提到的 post (@casten post) 中的步骤,但只是引发了一个新错误

2017-04-07 10:49:25.297 [ERROR][Thread-20][j.e.system.tools.deployment.common]Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: javax/servlet/ServletContainerInitializer
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:168)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:353)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:501)
    at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:406)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.load(InstallerThread.java:211)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.run(InstallerThread.java:100)
2017-04-07 10:49:25.297 [ERROR][Thread-20][javax.enterprise.system.core]Exception during lifecycle processing
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: javax/servlet/ServletContainerInitializer
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:168)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:353)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:501)
    at com.sun.enterprise.v3.server.ApplicationLoaderService.processApplication(ApplicationLoaderService.java:406)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.load(InstallerThread.java:211)
    at com.sun.enterprise.v3.admin.adapter.InstallerThread.run(InstallerThread.java:100)

我只是回滚 jars 位置。

谁能帮我找到正确的使用方法RollingFileAppender


非常感谢您!

我真丢人……我的问题是打错了……

<appender name="WSDLR" class="ch.qos.logback.core.RollingFileAppender">
    <file>${dir}/dt_wsdlr.log</file>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${dir}/dt_wsdlr-%d{yyyy.MM.dd}.log</fileNamePattern>
        <maxHistory>90</maxHistory>
        <totalSizeCap>3GB</totalSizeCap>
    </rollingPolicy>

    <encoder>
        <Pattern>${pattern}</Pattern>
    </encoder>
</appender>

正确的 class 引用是 ch.qos.logback.core.rolling.RollingFileAppender 而不是 ch.qos.logback.core.RollingFileAppender