我已经在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"));
:
要使用(稳定的 Glassfish 4)设置 logback Payara Server 4
,请按照@vzamanillo 在这篇文章中写的说明进行操作:
在那个指南(或其他找到的)人们使用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
在我的代码中使用引用时,与附加程序关联的文件根本没有被创建并且日志只是丢失了。
我尝试应用上面提到的帖子(@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
?
非常感谢您!