在Payara Server

时间:2017-04-07 18:32:52

标签: java logback glassfish-4 payara

我已经搜索了stackoverflow并且谷歌很多,但我的问题还没有解决。

问题:

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

@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)设置回溯,请按照@vzamanillo在此帖中所写的说明进行操作:

cannot get SLF4J working with glassfish 4

在该指南(或其他找到的)中,人们使用ch.qos.logback.core.FileAppender。使用此appender logback工作得很好,但我需要旋转日志文件。然后我只需在ch.qos.logback.core.rolling.RollingFileAppender中设置logback.xml,就像这样:

<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引用时,与appender关联的文件根本就没有创建,日志只是缺失

我尝试应用上面提到的帖子中的步骤(@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)

我只是回滚罐子的位置。

有人可以帮我找到使用RollingFileAppender的正确方法吗?

非常感谢你!

1 个答案:

答案 0 :(得分:0)

对我感到羞耻......我的问题是一个错字......

async

正确的类引用是<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> 而不是ch.qos.logback.core.rolling.RollingFileAppender