-
1. Re: Logback JBoss 7
jamezp Mar 13, 2013 11:02 PM (in response to klind)I don't think a relative path like that will work. Also it would need to be passed in at the end after -Djboss.home.dir.
Are you using any special appenders? If not you could just use the logging subsystem.
--
James R. Perkins
-
2. Re: Logback JBoss 7
klind Mar 14, 2013 11:29 AM (in response to jamezp)here is my logback.xml
<configuration scan="true" scanPeriod="30 seconds" > <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <target>System.out</target> <encoder> <pattern>[%p] %d [%c{1}] - %m%n</pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>/log/jsi.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern> </rollingPolicy> <append>true</append> <encoder> <pattern>[%p] %d [%c] - %m%n</pattern> </encoder> </appender> <appender name="MAIL" class="ch.qos.logback.classic.net.SMTPAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>ERROR</level> </filter> <smtpHost></smtpHost> <to></to> <from></from> <subject>Error on Deployment Stack</subject> <layout> <pattern>[%p] %d [%c{1}] - %m%n</pattern> </layout> <cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTrackerImpl"> <bufferSize>256</bufferSize> </cyclicBufferTracker> </appender> <root level="INFO"> <appender-ref ref="CONSOLE"/> <appender-ref ref="FILE"/> <appender-ref ref="MAIL"/> </root> </configuration>
There must be people using logback with JBoss 7
-
3. Re: Logback JBoss 7
jamezp Mar 14, 2013 12:26 PM (in response to klind)Using logback in your application shouldn't be an issue. I have to admit I'm not all that familiar with logback, so forgive me if these are obvious questions.
Are you providing a logback JAR in your deployment?
Does logback automatically find configuration files when activated? Or in other words is there something you need to do to activate it?
You're standalone.bat (while I do encourage you not to change it) should look more like
set LOGBACK_CONF_FILE=-Dlogback.configurationFile=%JBOSS_CONFIG_DIR%\logback.xml "%JAVA%" %JAVA_OPTS% ^ "-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\boot.log" ^ "-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^ -jar "%JBOSS_HOME%\jboss-modules.jar" ^ -mp "%JBOSS_MODULEPATH%" ^ -jaxpmodule "javax.xml.jaxp-provider" ^ org.jboss.as.standalone ^ -Djboss.home.dir="%JBOSS_HOME%" ^ %LOGBACK_CONF_FILE% ^ %*
If logback spits out debug information you might want to try enabling debug to see what it's saying.
--
James R. Perkins
-
4. Re: Logback JBoss 7
klind Mar 14, 2013 12:52 PM (in response to jamezp)I provide the
logback-classic-1.0.9.jar
logback-core-1.0.9.jar
slf4j-api-1.7.2.jar
in my app.
This is my jboss-deployment-structure.xml
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <ear-subdeployments-isolated>false</ear-subdeployments-isolated> <deployment> <exclusions> <!-- Exclude hibernate as we use the latest hibenate that we provide. see JSI/pom.xml --> <module name="org.hibernate" /> <module name="org.hibernate.validator" /> <!-- Exclude slf4j 1.6.1, we provide 1.7.2 --> <module name="org.apache.commons.logging" /> <module name="org.slf4j" /> <module name="org.slf4j.ext" /> <!-- Exclude slf4j-jboss-logmanager --> <module name="org.slf4j.impl" /> <module name="org.apache.log4j" /> </exclusions> </deployment> </jboss-deployment-structure>
Off cause I do not want to provide the logback.xml file, as I should be able to edit it at runtime.
logback will try to find configuration files. From the logback doc...
http://logback.qos.ch/manual/configuration.html
Let us begin by discussing the initialization steps that logback follows to try to configure itself: Logback tries to find a file called logback.groovy in the classpath. If no such file is found, logback tries to find a file called logback-test.xml in the classpath. If no such file is found, it checks for the file logback.xml in the classpath.. If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console. .... .... Specifying the location of the default configuration file as a system property You may specify the location of the default configuration file with a system property named"logback.configurationFile". The value of this property can be a URL, a resource on the class path or a path to a file external to the application. java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
I also moved the %LOGBACK_CONF_FILE%
"%JAVA%" %JAVA_OPTS% ^ "-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\boot.log" ^ "-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^ -jar "%JBOSS_HOME%\jboss-modules.jar" ^ -mp "%JBOSS_MODULEPATH%" ^ -jaxpmodule "javax.xml.jaxp-provider" ^ org.jboss.as.standalone ^ -Djboss.home.dir="%JBOSS_HOME%" ^ %LOGBACK_CONF_FILE% ^ %*
-
5. Re: Logback JBoss 7
klind Mar 14, 2013 1:42 PM (in response to klind)I also tried to add logback as a module... and no longer provide the logback in the app
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <ear-subdeployments-isolated>false</ear-subdeployments-isolated> <deployment> <exclusions> <!-- Exclude hibernate as we use the latest hibenate that we provide. see JSI/pom.xml --> <module name="org.hibernate" /> <module name="org.hibernate.validator" /> <!-- Exclude slf4j 1.6.1, we provide 1.7.2 --> <module name="org.apache.commons.logging" /> <module name="org.slf4j" /> <module name="org.slf4j.ext" /> <!-- Exclude slf4j-jboss-logmanager --> <module name="org.slf4j.impl" /> <module name="org.apache.log4j" /> </exclusions> <dependencies> <module name="ch.qos.logback" /> </dependencies> </deployment> </jboss-deployment-structure>
But nothing is happening..
I am wondering if slf4j is picking up some other implementation.. but I excluded slf4j-jboss-logmanager
-
6. Re: Logback JBoss 7
klind Mar 14, 2013 2:43 PM (in response to klind)I can see this in the server log... so the module id getring loaded..
but look at the last line....
11:32:36,926 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-3) Adding dependency ModuleDependency [identifier=ch.qos.logback:main, moduleLoader=Service Module Loader, export=false, optional=false, importServices=false] to module deployment.jsi-3.30.2-SNAPSHOT.ear:main 11:32:37,177 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-7) Adding dependency ModuleDependency [identifier=ch.qos.logback:main, moduleLoader=Service Module Loader, export=false, optional=false, importServices=false] to module deployment.jsi-3.30.2-SNAPSHOT.ear.dashboard.war:main 11:32:37,296 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-4) Adding dependency ModuleDependency [identifier=ch.qos.logback:main, moduleLoader=Service Module Loader, export=false, optional=false, importServices=false] to module deployment.jsi-3.30.2-SNAPSHOT.ear.profitMock.war:main 11:32:37,474 TRACE [org.jboss.modules] (MSC service thread 1-12) Locally loading module ch.qos.logback:main from local module loader @6e90891 (roots: C:\jboss\modules) 11:32:39,660 TRACE [org.jboss.modules] (MSC service thread 1-11) No local specification found for class org.slf4j.Logger in Module "ch.qos.logback:main" from local module loader @6e90891 (roots: C:\jboss\modules)
-
7. Re: Logback JBoss 7
jamezp Mar 14, 2013 2:52 PM (in response to klind)1 of 1 people found this helpfulIt looks like you need to add a dependency to the org.slf4j to your ch.qos.logback module.xml.
--
James R. Perkins -
8. Re: Logback JBoss 7
klind Mar 14, 2013 5:38 PM (in response to jamezp)I added slf4j as a module.
and added dependency in logback module..
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="ch.qos.logback"> <resources> <resource-root path="logback-classic-1.0.9.jar"/> <resource-root path="logback-core-1.0.9.jar"/> </resources> <dependencies> <module name="org.slf4j" slot="1.7.2" /> </dependencies> </module>
And no longer provide logback or slf4j in the app.
Added sub deployment... dont know if that is neccesary though...
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <ear-subdeployments-isolated>false</ear-subdeployments-isolated> <deployment> <exclusions> <!-- Exclude hibernate as we use the latest hibenate that we provide. see JSI/pom.xml --> <module name="org.hibernate" /> <module name="org.hibernate.validator" /> <!-- Exclude slf4j 1.6.1, we provide 1.7.2 --> <module name="org.apache.commons.logging" /> <module name="org.slf4j" /> <module name="org.slf4j.ext" /> <!-- Exclude slf4j-jboss-logmanager --> <module name="org.slf4j.impl" /> <module name="org.apache.log4j" /> </exclusions> <dependencies> <module name="ch.qos.logback" /> <module name="org.slf4j" slot="1.7.2"/> </dependencies> </deployment> <sub-deployment name="dashboard.war"> <exclusions> <!-- Exclude hibernate as we use the latest hibenate that we provide. see JSI/pom.xml --> <module name="org.hibernate" /> <module name="org.hibernate.validator" /> <!-- Exclude slf4j 1.6.1, we provide 1.7.2 --> <module name="org.apache.commons.logging" /> <module name="org.slf4j" /> <module name="org.slf4j.ext" /> <!-- Exclude slf4j-jboss-logmanager --> <module name="org.slf4j.impl" /> <module name="org.apache.log4j" /> </exclusions> <dependencies> <module name="ch.qos.logback" /> <module name="org.slf4j" slot="1.7.2"/> </dependencies> </sub-deployment> <sub-deployment name="profitMock.war"> <exclusions> <!-- Exclude hibernate as we use the latest hibenate that we provide. see JSI/pom.xml --> <module name="org.hibernate" /> <module name="org.hibernate.validator" /> <!-- Exclude slf4j 1.6.1, we provide 1.7.2 --> <module name="org.apache.commons.logging" /> <module name="org.slf4j" /> <module name="org.slf4j.ext" /> <!-- Exclude slf4j-jboss-logmanager --> <module name="org.slf4j.impl" /> <module name="org.apache.log4j" /> </exclusions> <dependencies> <module name="ch.qos.logback" /> <module name="org.slf4j" slot="1.7.2"/> </dependencies> </sub-deployment> </jboss-deployment-structure>
Now the log shows :
13:16:05,973 TRACE [org.jboss.modules] (MSC service thread 1-3) Locally loading module ch.qos.logback:main from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:05,978 DEBUG [org.jboss.modules] (MSC service thread 1-3) Module ch.qos.logback:main defined by local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,196 TRACE [org.jboss.modules] (MSC service thread 1-11) Finding local class org.slf4j.Logger from Module "ch.qos.logback:main" from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,205 TRACE [org.jboss.modules] (MSC service thread 1-11) Loading class org.slf4j.Logger locally from Module "ch.qos.logback:main" from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,207 TRACE [org.jboss.modules] (MSC service thread 1-11) No local specification found for class org.slf4j.Logger in Module "ch.qos.logback:main" from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,209 TRACE [org.jboss.modules] (MSC service thread 1-11) Finding local class org.slf4j.Logger from Module "org.slf4j:1.7.2" from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,210 TRACE [org.jboss.modules] (MSC service thread 1-11) Loading class org.slf4j.Logger locally from Module "org.slf4j:1.7.2" from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,212 TRACE [org.jboss.modules] (MSC service thread 1-11) Attempting to define class org.slf4j.Logger in Module "org.slf4j:1.7.2" from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,213 TRACE [org.jboss.modules] (MSC service thread 1-11) Attempting to define package org.slf4j in Module "org.slf4j:1.7.2" from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,215 TRACE [org.jboss.modules] (MSC service thread 1-11) Defined package org.slf4j in Module "org.slf4j:1.7.2" from local module loader @6e90891 (roots: C:\jboss\modules) 13:16:08,217 TRACE [org.jboss.modules] (MSC service thread 1-11) Defined class org.slf4j.Logger in Module "org.slf4j:1.7.2" from local module loader @6e90891 (roots: C:\jboss\modules)
When calling a webservice that should log something I get this... :
14:37:37,272 ERROR [stderr] (http--127.0.0.1-8080-1) SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 14:37:37,274 ERROR [stderr] (http--127.0.0.1-8080-1) SLF4J: Defaulting to no-operation (NOP) logger implementation 14:37:37,275 ERROR [stderr] (http--127.0.0.1-8080-1) SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
-
9. Re: Logback JBoss 7
klind Mar 14, 2013 6:33 PM (in response to klind)SLF4J is not picking up the logback... even though I have the
<dependencies>
<module name="ch.qos.logback" />
<module name="org.slf4j" slot="1.7.2"/>
</dependencies>In the jboss-deployment-structure.xml
Also if I provide the logback jar files in my ear/lib the result is the same..
-
10. Re: Logback JBoss 7
jamezp Mar 14, 2013 6:38 PM (in response to klind)That slot looks wrong. It should be main or empty really.
--
James R. Perkins
-
11. Re: Logback JBoss 7
klind Mar 14, 2013 6:43 PM (in response to jamezp)I put in my slf4j as slot 1.7.2...
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="org.slf4j" slot="1.7.2"> <resources> <resource-root path="slf4j-api-1.7.2.jar"/> <!-- Insert resources here --> </resources> </module>
The native slf4j is still there.. which is the main
<module xmlns="urn:jboss:module:1.1" name="org.slf4j"> <resources> <resource-root path="slf4j-api-1.6.1.jar"/> <!-- Insert resources here --> </resources> <dependencies> <module name="org.slf4j.impl"/> </dependencies> </module>
And log shows that version 1.7.2 is loaded...
13:29:26,378 TRACE [org.jboss.modules] (MSC service thread 1-15) Locally loading module org.slf4j:1.7.2 from local module loader @6e90891 (roots: C:\jboss\modules) 13:29:26,382 DEBUG [org.jboss.modules] (MSC service thread 1-15) Module org.slf4j:1.7.2 defined by local module loader @6e90891 (roots: C:\jboss\modules) 13:29:26,383 TRACE [org.jboss.modules] (MSC service thread 1-15) Loaded module org.slf4j:1.7.2 from local module loader @6e90891 (roots: C:\jboss\modules)
-
12. Re: Logback JBoss 7
jamezp Mar 14, 2013 6:54 PM (in response to klind)Ah, I should have noticed the version difference :-)
It might need a circular dependency. Try adding the ch.qos.logback to your slf4j module.
--
James R. Perkins
-
13. Re: Logback JBoss 7
klind Mar 14, 2013 7:11 PM (in response to jamezp)1 of 1 people found this helpfulI wouldn't think so, as slf4j should just look for a binding implementation in the class path.. and here find logback.
If I debug my code and break on a log.debug line, I can see the the instance of log, is a org.slf4j.helpers.NOPLogger(NOP), which is used when no binding can be found on the class path..
But i will try it
-
14. Re: Logback JBoss 7
klind Mar 14, 2013 7:22 PM (in response to klind)Actually something did happen...
16:19:47,592 ERROR [stderr] (MSC service thread 1-12) Failed to instantiate [ch.qos.logback.classic.LoggerContext] 16:19:47,595 ERROR [stderr] (MSC service thread 1-12) Reported exception: 16:19:47,598 ERROR [stderr] (MSC service thread 1-12) java.lang.NoClassDefFoundError: org/xml/sax/InputSource 16:19:47,601 ERROR [stderr] (MSC service thread 1-12) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:106) 16:19:47,604 ERROR [stderr] (MSC service thread 1-12) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:56) 16:19:47,607 ERROR [stderr] (MSC service thread 1-12) at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75) 16:19:47,610 ERROR [stderr] (MSC service thread 1-12) at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148) 16:19:47,613 ERROR [stderr] (MSC service thread 1-12) at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
But I have xml-apis-2.9.1.jar in my ear/lib, but I guess the module classloader cannot see that.
So do I now have to create modules for all the dependencies logback has ??