2014-09-25 66 views
2

我有一個使用嵌入式Jetty的應用程序。一切都很好,除了伐木。我現在正在嘗試使用logback,但正在發生致命錯誤。使用嵌入式Jetty無法使日誌記錄正常工作

的應用程序加載時,你可以看到:

$ java -XX:+UseConcMarkSweepGC -XX:PermSize=64M -XX:MaxPermSize=256M -Xms1G -Xmx1G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -jar /usr/local/mexp/mexp.jar server /usr/local/mexp/mexp.json 
10:46:02.093 [main] DEBUG org.eclipse.jetty.util.log - Logging to Logger[org.eclipse.jetty.util.log] via org.eclipse.jetty.util.log.Slf4jLog 
10:46:02.098 [main] INFO org.eclipse.jetty.util.log - Logging initialized @76ms 

其次是頁面和描述我的應用程序每一個類裝載調試語句的網頁。這表明它沒有找到logback.xml,我已經將org.eclipse.jetty的日誌級別設置爲ERROR。

最終,我得到以下異常時,應用程序加載:

10:46:30.349 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - loaded class org.slf4j.impl.StaticLoggerBinder from [email protected] 
10:46:30.354 [main] WARN o.e.j.u.component.AbstractLifeCycle - FAILED [email protected]{/,file:/usr/local/mexp/resources/webapp/,STARTING}{file:/usr/local/mexp/mexp.jar}: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/eclipse/jetty/webapp/WebAppClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature 
java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/eclipse/jetty/webapp/WebAppClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature 
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:306) ~[mexp.jar:na] 
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276) ~[mexp.jar:na] 
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:288) ~[mexp.jar:na] 
    at com.rc.util.logging.RCLog.<init>(RCLog.java:28) ~[mexp.jar:na] 
    at com.rc.commonwebapp.servlet.filter.SessionTXManager.<init>(SessionTXManager.java:43) ~[na:na] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_45] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_45] 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_45] 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_45] 
    at java.lang.Class.newInstance(Class.java:374) ~[na:1.7.0_45] 
    at org.eclipse.jetty.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2370) ~[mexp.jar:na] 
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createFilter(ServletContextHandler.java:1146) ~[mexp.jar:na] 
    at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:120) ~[mexp.jar:na] 
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:850) ~[mexp.jar:na] 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298) ~[mexp.jar:na] 
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1341) ~[mexp.jar:na] 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1334) ~[mexp.jar:na] 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) ~[mexp.jar:na] 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497) ~[mexp.jar:na] 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [mexp.jar:na] 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) [mexp.jar:na] 
    at org.eclipse.jetty.server.Server.start(Server.java:380) [mexp.jar:na] 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) [mexp.jar:na] 
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) [mexp.jar:na] 
    at org.eclipse.jetty.server.Server.doStart(Server.java:347) [mexp.jar:na] 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [mexp.jar:na] 
    at com.pronto.JettyWebApp.main(JettyWebApp.java:95) [mexp.jar:na] 

java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/eclipse/jetty/webapp/WebAppClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature 
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:306) ~[mexp.jar:na] 
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276) ~[mexp.jar:na] 
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:288) ~[mexp.jar:na] 
    at com.rc.util.logging.RCLog.<init>(RCLog.java:28) ~[mexp.jar:na] 
    at com.rc.commonwebapp.servlet.filter.SessionTXManager.<init>(SessionTXManager.java:43) ~[na:na] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_45] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_45] 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_45] 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_45] 
    at java.lang.Class.newInstance(Class.java:374) ~[na:1.7.0_45] 
    at org.eclipse.jetty.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2370) ~[mexp.jar:na] 
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createFilter(ServletContextHandler.java:1146) ~[mexp.jar:na] 
    at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:120) ~[mexp.jar:na] 
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:850) ~[mexp.jar:na] 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298) ~[mexp.jar:na] 
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1341) ~[mexp.jar:na] 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1334) ~[mexp.jar:na] 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) ~[mexp.jar:na] 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497) ~[mexp.jar:na] 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[mexp.jar:na] 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) ~[mexp.jar:na] 
    at org.eclipse.jetty.server.Server.start(Server.java:380) ~[mexp.jar:na] 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) ~[mexp.jar:na] 
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) ~[mexp.jar:na] 
    at org.eclipse.jetty.server.Server.doStart(Server.java:347) ~[mexp.jar:na] 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[mexp.jar:na] 
    at com.pronto.JettyWebApp.main(JettyWebApp.java:95) [mexp.jar:na] 
Exception in thread "main" java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/eclipse/jetty/webapp/WebAppClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type LoggerFactory; used in the signature 
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:306) 
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:276) 
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:288) 
    at com.rc.util.logging.RCLog.<init>(RCLog.java:28) 
    at com.rc.commonwebapp.servlet.filter.SessionTXManager.<init>(SessionTXManager.java:43) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
    at java.lang.Class.newInstance(Class.java:374) 
    at org.eclipse.jetty.server.handler.ContextHandler$Context.createInstance(ContextHandler.java:2370) 
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createFilter(ServletContextHandler.java:1146) 
    at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:120) 
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:850) 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298) 
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1341) 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1334) 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) 
    at org.eclipse.jetty.server.Server.start(Server.java:380) 
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) 
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) 
    at org.eclipse.jetty.server.Server.doStart(Server.java:347) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at com.pronto.JettyWebApp.main(JettyWebApp.java:95) 

一些網絡上搜索java.lang.LinkageError的建議,Jetty和我的應用程序有不同的類在嘗試加載LoggerFactory時發生衝突的加載器。我不確定接下來要做什麼。

ETA: 每@ PavelHoral的建議我加入<scope>provided</scope>我的pom.xml(dependencyManagement部分),但在這個結果時,我嘗試啓動應用程序:

2014-09-28 16:47:42.491:INFO::main: Logging initialized @66ms 
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 
    at com.rc.util.config.ConfigurationManager.<clinit>(ConfigurationManager.java:31) 
    at com.pronto.JettyWebApp.main(JettyWebApp.java:39) 
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    ... 2 more 

ETA:由每建議@ HD1我添加了橋,它擺脫了LinkageError,所以我們在那裏。我仍然因爲所有的日誌記錄轉到stdout而仍然處於DEBUG級別這一事實 - 對於產品環境來說當然是不可接受的,所以我需要能夠配置它。這是我的logback.xml:

<configuration> 
    <appender name="FILE" class="ch.qos.logback.core.FileAppender"> 
     <file>/usr/local/mexp/logs/mexp.service.log</file> 
     <encoder> 
      <pattern>"%-5p [%d{dd-MMM-yy HH:mm:ss}] [%t] %-20c %-3x:%m%n</pattern> 
     </encoder> 
    </appender> 

    <appender name="AXIS" class="ch.qos.logback.core.FileAppender"> 
     <file>/usr/local/mexp/logs/axis.log</file> 
     <encoder> 
      <pattern>%-5p [%d{dd-MMM-yy HH:mm:ss}] :%m%n</pattern> 
     </encoder> 
    </appender> 

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> 
     <!-- The default pattern: Date Priority [Category] Message\n --> 
     <encoder> 
      <pattern>%d{ABSOLUTE} %-5p [%c{1}] %m%n</pattern> 
     </encoder> 
    </appender> 

    <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender"> 
     <appender-ref ref="AXIS"/> 
    </appender> 

    <logger name="org.apache"> 
     <level value="ERROR"/> 
    </logger> 

    <logger name="org.quartz"> 
     <level value="ERROR" /> 
    </logger> 

    <logger name="org.hibernate"> 
     <level value="ERROR" /> 
    </logger> 

    <logger name="org.apache.struts.action"> 
     <level value="INFO"/> 
    </logger> 

    <logger name="org.apache.catalina.cluster"> 
     <level value="INFO"/> 
    </logger> 

    <logger name="org"> 
     <level value="ERROR" /> 
    </logger> 

    <logger name="net"> 
     <level value="ERROR" /> 
    </logger> 

    <logger name="org.apache.axis.transport.http.HTTPSender" additivity="false"> 
     <level value="ERROR"/> 
     <appender-ref ref="ASYNC"/> 
    </logger> 

    <logger name="com.mchange"> 
     <level value="ERROR"/> 
    </logger> 

    <!-- this silences the HttpClient chatter that starts with "httpclient.wire.header" and "httpclient.wire.content" --> 
    <logger name="org.apache.commons.httpclient"> 
     <level value="fatal"/> 
    </logger> 
    <logger name="httpclient.wire.header"> 
     <level value="fatal"/> 
    </logger> 
    <logger name="httpclient.wire.content"> 
     <level value="fatal"/> 
    </logger> 

    <logger name="org.eclipse.jetty"> 
     <level value="ERROR"/> 
    </logger> 

    <!-- Log the real SQL --> 
    <logger name="org.hibernate.SQL"> 
     <level value="ERROR"/> 
    </logger> 

    <root level="ERROR"> 
     <appender-ref ref="FILE"/> 
    </root> 
</configuration> 

ETA:我還試圖記錄分離描述here - 將此添加到web.xml中:

<env-entry> 
    <env-entry-name>logback/context-name</env-entry-name> 
    <env-entry-type>java.lang.String</env-entry-type> 
    <env-entry-value>mexp</env-entry-value> 
</env-entry> 

和這在我的碼頭轉輪主要方法

System.setProperty("logback.ContextSelector", "JNDI"); 

(並將logback文件的名稱更改爲logback-mexp.xml),但所有這些都不會導致行爲更改。

我們肯定會越來越近,但對於賞金我需要整個解決方案。謝謝!


ETA當前狀態的東西。我不再收到LinkageError。我的應用程序加載並執行正常。事實上,現在我已經有了相當大的改進,現在我不會在標準輸出中獲得DEBUG行的頁面和頁面。我仍然得到我所有的stdout日誌記錄,如下所示:

$ java -XX:+UseConcMarkSweepGC -XX:PermSize=64M -XX:MaxPermSize=256M -Xms1G -Xmx1G -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -jar /usr/local/mexp/mexp.jar server /usr/local/mexp/mexp.json 
Oct 01, 2014 3:54:28 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
INFO: Root WebApplicationContext: initialization started 
Oct 01, 2014 3:54:28 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh 
INFO: Refreshing Root WebApplicationContext: startup date [Wed Oct 01 15:54:28 EDT 2014]; root of context hierarchy 
Oct 01, 2014 3:54:28 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from class path resource [mexpPapiContext.xml] 
Oct 01, 2014 3:54:28 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
INFO: Root WebApplicationContext: initialization completed in 352 ms 
SLF4J: Class path contains multiple SLF4J bindings. 
SLF4J: Found binding in [jar:file:/usr/local/mexp/resources/webapp/WEB-INF/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: Found binding in [jar:file:/usr/local/mexp/mexp.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. 
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] 
15:54:28,596 INFO GlobalRootManager:85 - Entering initialization 
15:54:28,840 INFO GlobalRootManager:85 - Exiting initialization 
15:54:28,868 INFO FileUtil:220 - -> Found /mpds.properties in resource bundle 
Oct 01, 2014 3:54:29 PM org.apache.struts.action.ActionServlet initChain 
INFO: Loading chain catalog from jar:file:/usr/local/mexp/resources/webapp/WEB-INF/lib/struts-core-1.3.10.jar!/org/apache/struts/chain/chain-config.xml 
Oct 01, 2014 3:54:29 PM org.apache.struts.action.ActionServlet initChain 
INFO: Loading chain catalog from jar:file:/usr/local/mexp/mexp.jar!/org/apache/struts/chain/chain-config.xml 
Oct 01, 2014 3:54:29 PM org.apache.struts.validator.ValidatorPlugIn initResources 
INFO: Loading validation rules file from '/WEB-INF/struts/validator-rules.xml' 
Oct 01, 2014 3:54:29 PM org.apache.struts.validator.ValidatorPlugIn initResources 
INFO: Loading validation rules file from '/WEB-INF/struts/validation-mexp.xml' 
15:54:29,529 INFO QuartzStartupServlet:85 - Entering servlet init. 
15:54:29,562 INFO StdSchedulerFactory:1184 - Using default implementation for ThreadExecutor 
15:54:29,575 INFO SchedulerSignalerImpl:61 - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 
15:54:29,575 INFO QuartzScheduler:240 - Quartz Scheduler v.2.2.1 created. 
15:54:29,576 INFO XMLSchedulingDataProcessorPlugin:200 - Registering Quartz Job Initialization Plug-in. 
15:54:29,578 INFO RAMJobStore:155 - RAMJobStore initialized. 
15:54:29,578 INFO QuartzScheduler:305 - Scheduler meta-data: Quartz Scheduler (v2.2.1) 'MexpScheduler' with instanceId 'dev' 
    Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally. 
    NOT STARTED. 
    Currently in standby mode. 
    Number of jobs executed: 0 
    Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 5 threads. 
    Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. 

15:54:29,578 INFO StdSchedulerFactory:1339 - Quartz scheduler 'MexpScheduler' initialized from an externally provided properties instance. 
15:54:29,578 INFO StdSchedulerFactory:1343 - Quartz scheduler version: 2.2.1 
15:54:29,592 INFO XMLSchedulingDataProcessor:471 - Parsing XML file: mexp-dev-jobs.xml with systemId: mexp-dev-jobs.xml 
15:54:29,948 INFO XMLSchedulingDataProcessor:996 - Adding 13 jobs, 13 triggers. 
15:54:29,949 INFO XMLSchedulingDataProcessor:1034 - Adding job: skuLevelBiddingReportGroup.skuLevelBiddingReportJob 
15:54:29,951 INFO XMLSchedulingDataProcessor:1034 - Adding job: emailNotificationsGroup.emailNotificationsJob 
15:54:29,952 INFO XMLSchedulingDataProcessor:1034 - Adding job: balanceReplenishmentGroup.balanceReplenishmentJob 
15:54:29,953 INFO XMLSchedulingDataProcessor:1034 - Adding job: balanceReplenishmentCappedInvoiceGroup.balanceReplenishmentCappedInvoiceJob 
15:54:29,954 INFO XMLSchedulingDataProcessor:1034 - Adding job: merchantTxnProcessingGroup.merchantTxnProcessingJob 
15:54:29,956 INFO XMLSchedulingDataProcessor:1034 - Adding job: feedFileManagerGroup.feedFileManagerJob 
15:54:29,957 INFO XMLSchedulingDataProcessor:1034 - Adding job: merchantPaymentManagerGroup.merchantPaymentManagerJob 
15:54:29,958 INFO XMLSchedulingDataProcessor:1032 - Replacing job: merchantTxnProcessingGroup.merchantTxnProcessingJob 
15:54:29,958 INFO XMLSchedulingDataProcessor:1034 - Adding job: expiredAccountUpdaterGroup.expiredAccountUpdaterJob 
15:54:29,959 INFO XMLSchedulingDataProcessor:1034 - Adding job: placementsForDatasyncUpdaterGroup.placementsForDatasyncUpdaterJob 
15:54:29,960 INFO XMLSchedulingDataProcessor:1034 - Adding job: placementPaymentProcessingGroup.placementPaymentProcessingJob 
15:54:29,961 INFO XMLSchedulingDataProcessor:1034 - Adding job: switchingMerchantsToInvoiceGroup.switchingMerchantsToInvoiceJob 
15:54:29,962 INFO XMLSchedulingDataProcessor:1034 - Adding job: toggleActiveStateGroup.toggleActiveStateJob 
15:54:29,963 INFO QuartzScheduler:575 - Scheduler MexpScheduler_$_dev started. 
15:54:29,982 INFO LoggingTriggerHistoryPlugin:387 - Trigger JobSchedulingDataLoaderPlugin.JobSchedulingDataLoaderPlugin_jobInitializer_mexp-dev-jobs_xml fired job JobSchedulingDataLoaderPlugin.JobSchedulingDataLoaderPlugin_jobInitializer_mexp-dev-jobs_xml at: 15:54:29 10/01/2014 
15:54:29,983 INFO LoggingJobHistoryPlugin:469 - Job JobSchedulingDataLoaderPlugin.JobSchedulingDataLoaderPlugin_jobInitializer_mexp-dev-jobs_xml fired (by trigger JobSchedulingDataLoaderPlugin.JobSchedulingDataLoaderPlugin_jobInitializer_mexp-dev-jobs_xml) at: 15:54:29 10/01/2014 
15:54:29,984 INFO LoggingJobHistoryPlugin:513 - Job JobSchedulingDataLoaderPlugin.JobSchedulingDataLoaderPlugin_jobInitializer_mexp-dev-jobs_xml execution complete at 15:54:29 10/01/2014 and reports: null 
15:54:29,984 INFO LoggingTriggerHistoryPlugin:433 - Trigger JobSchedulingDataLoaderPlugin.JobSchedulingDataLoaderPlugin_jobInitializer_mexp-dev-jobs_xml completed firing job JobSchedulingDataLoaderPlugin.JobSchedulingDataLoaderPlugin_jobInitializer_mexp-dev-jobs_xml at 15:54:29 10/01/2014 with resulting trigger instruction code: DO NOTHING 
+0

你在使用Maven嗎?如果是這樣,請告訴我們你的依賴關係。或者更好,展示你的應用程序結構。這個錯誤表明你正在用你的webapp打包slf4j,但是也可以從你的可執行JAR的META-INF中引用它。我不是Jetty的專家,但其中的一個不應該在他們的classpath上有slf4j(可能是webapp)。 – 2014-09-28 15:39:16

+0

我正在使用maven。這是一個巨大的應用程序,有11個模塊和幾乎N-1的依賴關係。我很高興分享pom.xml,但我不想在這裏粘貼整個東西。 webapp和其他幾個模塊廣泛使用slf4j,所以我不確定我怎麼可以忽略它作爲依賴關係,並讓應用程序進行編譯。我已經在使用它的所有模塊中排除了slf4j,但它仍然包含在內。有沒有一種方法可以在沒有隨後在戰爭中包含依賴的情況下進行編譯(包含在uber-jar中)? – barclay 2014-09-28 18:09:19

+0

看起來'slf4j'找到多個'LoggerFactory'的實例。我可以使用'org.eclipse.jetty.util.log.Slf4jLog'來查看jetty日誌。我不習慣碼頭(使用tomcat ...),但碼頭記錄工作如何?如果您嘗試通過slf4j登錄而不將logback添加到類路徑,會發生什麼? slf4j是否嘗試使用碼頭日誌? – 2014-09-28 18:20:50

回答

3

請參閱this page on the slf4j site。我懷疑你沒有包含合適的橋樑罐。例如,對於log4j,你將需要在你的pom.xml以下節:

<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-api</artifactId> 
    <version>1.7.7</version> 
</dependency> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    <version>1.7.7</version> 
</dependency> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>log4j-over-slf4j</artifactId> 
    <version>1.7.7</version> 
</dependency> 

<dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>1.2.17</version> 
</dependency> 

希望有所幫助。如果沒有,請隨時發表評論。

+0

謝謝,但它沒有幫助。當我用log4j-over-slf4j替換log4j時仍然會得到相同的'java.lang.LinkageError'。 – barclay 2014-09-29 00:28:18

+0

你不會取代它,你添加橋罐到你的pom。我舉了一個你需要的例子。 – hd1 2014-09-29 04:03:41

+0

謝謝。我恢復了log4j include並添加了另外兩個依賴項;該應用程序啓動,並沒有LinkageError,這是偉大的!但是,日誌記錄仍然處於DEBUG級別,並且都轉到stdout。任何想法我需要做的下一步來獲取日誌使用我的配置?我在我的classpath中有一個logback.xml,我將在上面添加到我的原始文章中。 – barclay 2014-09-29 14:54:41

0

我不認爲這裏有一個銀色的子彈:登錄Java採取多種形式,它需要注意細節才能正確使用。尤其是當類加載器像網絡應用程序一樣進入遊戲時。

有關如何通過Joakim Erdfelt與Slf4j進行日誌記錄的解釋很不錯(我在前面看到過你在mail-conversation中的這個)。

我只能加做一個適當的清理:

  • 將JAR-文件的logback的SLF4J的API和所需SLF4J橋(JCL-過SLF4J,log4j的,在-slf4j)在主/通用/啓動類路徑中。
  • 刪除與日誌記錄(log4j,commons-logging等)有關的所有其他內容。 Pavel Horal在評論中提到的「範圍提供的依賴管理」技巧可以在這裏派上用場。
  • 對於需要以編程方式將Slf4j設置爲記錄器的某些組件,例如,對於Hibernate 4.3,在Hibernate啓動之前使用System.setProperty("org.jboss.logging.provider", "slf4j");
  • 如果Slf4j無法設置爲組件的記錄器,請嘗試設置Log4j。 slf4j-bridge「log4j-over-slf4j」會將日誌記錄從Log4j重定向到Slf4j,Slf4j會將其發送到日誌記錄實現(Logback)。請注意,您只需要在主要類路徑中使用bridge jar文件「log4j-over-slf4j」,而不是log4j-jar(該橋將爲Log4j類提供替代)。

現在你應該在你的整個組件只有一個JAR文件和/或類應用程序在清理的第一點提到的每個記錄相關組件。仔細檢查任何Web應用程序(WEB-INF/lib文件夾)中是否有與日誌記錄相關的jar文件。在一個側面節點上:如果使用JDBC驅動程序,請按照相同的步驟進行操作(如果它們不在主要類路徑中,這些程序也會帶來麻煩)。

在您開始清理之前,您應該使用內嵌了Jetty的Logback驗證您的基本設置Hello World example

需要一些努力才能使所有這些日誌記錄正常進行,但正如您所說,它是生產所必需的,它在開發過程中對我有幫助:只需打開第三方組件的跟蹤/調試(通過記錄器) logback-test.xml中的類別)可以提供關於發生的事情的大量信息(尤其是與單元測試結合使用時)。

+0

我嘗試了所有這些想法,但沒有任何幫助。 – barclay 2014-10-06 14:22:04

0

我有這個問題。原來,我發現了一個令人難以忍受的容易溶劑(在我的情況)。

Jetty沒有找到我的slf4j - *。jar(s),除非我將它們作爲依賴項添加到插件配置本身。我不會包含我的整個pom.xml,而只是插件conf。希望這可以幫助。

乾杯

... 
    <plugin> 
<groupId>org.mortbay.jetty</groupId> 
<artifactId>jetty-maven-plugin</artifactId> 
<version>8.1.10.v20130312</version> 
<configuration> 
    <webAppConfig> 
    </webAppConfig> 
</configuration> 
<dependencies> 
    <dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-api</artifactId> 
    <version>1.7.7</version> 
    </dependency> 
    <dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    <version>1.7.7</version> 
    </dependency> 
    <dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>log4j-over-slf4j</artifactId> 
    <version>1.7.7</version> 
    </dependency> 
    <dependency> 
    <groupId>org.codehaus.fabric3</groupId> 
    <artifactId>fabric3-atomikos-library</artifactId> 
    <version>1.9.6</version> 
    </dependency> 
    <dependency> 
    <groupId>javax.transaction</groupId> 
    <artifactId>jta</artifactId> 
    <version>1.1</version> 
    <scope>runtime</scope> 
    </dependency> 
     <dependency> 
     <groupId>org.codehaus.btm</groupId> 
     <artifactId>btm-jetty6-lifecycle</artifactId> 
     <version>1.3.3</version> 
     </dependency> 
</dependencies> 
    </plugin> 
... 

我再檢查使用Maven的依賴插件項目依賴關係樹和刪除/排除的依賴關係包括了所有不必要的日誌框架和它的工作。

相關問題