[logback-user] Migrating from log4j

Taariq taariql at gmail.com
Thu Apr 21 21:32:36 CEST 2011


Thanks David, that worked.

Its actually cocoon-spring-configurator with the optional log4j dependency.
Excluding all log4j and commons-logging did the trick.

Thanks again,
Taariq

On 21 Apr 2011, at 8:32 PM, David Roussel <nabble at diroussel.xsmail.com> wrote:

> I don't know what the problem is, but spring doesn't depend on log4j, it uses commons logging. Make sure you don't have commons-logging on your classpath and the you have the commons to slf4j bridge.
>
> Maybe fixing that will solve your problem.
>
> David
>
> On 21 Apr 2011, at 10:04, Taariq <taariql at gmail.com> wrote:
>
>> Hi
>>
>> I'm migrating an app from log4j, which uses a daily rolling file
>> appender defined like this...
>>
>> log4j.rootLogger=ERROR
>>
>> ### file appender
>> log4j.appender.GTISFile=org.apache.log4j.DailyRollingFileAppender
>> log4j.appender.GTISFile.layout.ConversionPattern=%d{ABSOLUTE} %5p
>> %c{1}:%L - %m%n
>> log4j.appender.GTISFile.layout=org.apache.log4j.PatternLayout
>> log4j.appender.GTISFile.File="${user.home}/log/gtis.log"
>>
>>
>> This will create a file named gtis.log in my user home directory, in a
>> sub directory called log.
>>
>> The logback config to attempt the same...
>>        <appender name="GTISFile"
>> class="ch.qos.logback.core.rolling.RollingFileAppender">
>>
>>       <File>"${user.home}/log/gtis.log"</File>
>>       <encoder>
>>           <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
>> %msg%n</pattern>
>>       </encoder>
>>
>>       <rollingPolicy
>> class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
>>           <!-- daily rollover -->
>>           <fileNamePattern>.%d{yyyy-MM-dd}.log</fileNamePattern>
>>
>>           <!-- keep 30 days' worth of history -->
>>           <maxHistory>30</maxHistory>
>>       </rollingPolicy>
>>   </appender>
>>
>> Now first I have to mention I'm using spring and other libraries that
>> depend on log4j, so I'm using
>> logback-classic 0.9.28, log4j-over-slf4j and slf4j-api 1.6.1
>>
>> As such I've got both the log4j.properties file and the logback.xml in
>> the classpath, hoping that
>> logback handle all calls to log4j. If this is wrong please let me know.
>>
>> This results in the errors below in both log4j and logback. It seems
>> to want to create "C:\Users\TaariqL\log\gtis.log" inside my working
>> directory.
>> If I don't try to use the user.home or user.dir directories, eg
>> <fileNamePattern>log/gtis.%d{yyyy-MM-dd}.log</fileNamePattern>, then
>> it works fine
>> and creates the log file in a folder called log inside my working directory.
>> How does logback support the behaviour I had with log4j?
>>
>> Thanks,
>> Taariq
>>
>> log4j:ERROR setFile(null,true) call failed.
>> java.io.FileNotFoundException: "C:\Users\TaariqL\log\gtis.log" (The
>> filename, directory name, or volume label syntax is incorrect)
>>   at java.io.FileOutputStream.openAppend(Native Method)
>>   at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
>>   at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
>>   at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)
>>   at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)
>>   at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:215)
>>   at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)
>>   at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:132)
>>   at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:96)
>>   at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:654)
>>   at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:612)
>>   at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:509)
>>   at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:415)
>>   at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:441)
>>   at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:468)
>>   at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
>>   at org.apache.log4j.Logger.getLogger(Logger.java:104)
>>   at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:283)
>>   at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:108)
>>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>   at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1040)
>>   at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:838)
>>   at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:601)
>>   at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:333)
>>   at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:307)
>>   at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
>>   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<clinit>(SpringJUnit4ClassRunner.java:90)
>>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>   at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
>>   at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
>>   at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
>>   at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
>>   at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
>>   at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:93)
>>   at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:84)
>>   at org.junit.runners.Suite.<init>(Suite.java:79)
>>   at com.intellij.junit4.IdeaSuite.<init>(IdeaSuite.java:40)
>>   at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:34)
>>   at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:81)
>>   at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:64)
>>   at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:196)
>>   at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
>>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>   at java.lang.reflect.Method.invoke(Method.java:597)
>>   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
>> log4j:ERROR Either File or DatePattern options are not set for
>> appender [GTISFile].
>> 10:56:00,063 |-INFO in ch.qos.logback.classic.LoggerContext[default] -
>> Could NOT find resource [logback.groovy]
>> 10:56:00,064 |-INFO in ch.qos.logback.classic.LoggerContext[default] -
>> Found resource [logback-test.xml] at
>> [file:/C:/Users/TaariqL/Documents/Workspace/GTIS_Trunk/gtis-core/target/test-classes/logback-test.xml]
>> 10:56:00,256 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
>> - About to instantiate appender of type
>> [ch.qos.logback.core.rolling.RollingFileAppender]
>> 10:56:00,261 |-INFO in ch.qos.logback.core.joran.action.AppenderAction
>> - Naming appender as [GTISFile]
>> 10:56:00,284 |-INFO in
>> ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming
>> default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for
>> [encoder] property
>> 10:56:00,349 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No
>> compression will be used
>> 10:56:00,351 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy -
>> Will use the pattern .%d{yyyy-MM-dd}.log for the active file
>> 10:56:00,356 |-INFO in
>> c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The
>> date pattern is 'yyyy-MM-dd' from file name pattern
>> '.%d{yyyy-MM-dd}.log'.
>> 10:56:00,356 |-INFO in
>> c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy -
>> Roll-over at midnight.
>> 10:56:00,359 |-INFO in
>> c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy -
>> Setting initial period to Thu Apr 21 10:56:00 CAT 2011
>> 10:56:00,360 |-INFO in
>> ch.qos.logback.core.rolling.RollingFileAppender[GTISFile] - Active log
>> file name: "C:\Users\TaariqL/log/gtis.log"
>> 10:56:00,360 |-INFO in
>> ch.qos.logback.core.rolling.RollingFileAppender[GTISFile] - File
>> property is set to ["C:\Users\TaariqL/log/gtis.log"]
>> 10:56:00,362 |-ERROR in
>> ch.qos.logback.core.rolling.RollingFileAppender[GTISFile] - Failed to
>> create parent directories for
>> [C:\Users\TaariqL\Documents\Workspace\GTIS_Trunk\"C:\Users\TaariqL\log\gtis.log"]
>> 10:56:00,363 |-ERROR in
>> ch.qos.logback.core.rolling.RollingFileAppender[GTISFile] -
>> openFile("C:\Users\TaariqL/log/gtis.log",true) call failed.
>> java.io.FileNotFoundException: "C:\Users\TaariqL\log\gtis.log" (The
>> filename, directory name, or volume label syntax is incorrect)
>>   at java.io.FileNotFoundException: "C:\Users\TaariqL\log\gtis.log"
>> (The filename, directory name, or volume label syntax is incorrect)
>>   at    at java.io.FileOutputStream.openAppend(Native Method)
>>   at    at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
>>   at    at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(ResilientFileOutputStream.java:30)
>>   at    at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:163)
>>   at    at ch.qos.logback.core.FileAppender.start(FileAppender.java:115)
>>   at    at ch.qos.logback.core.rolling.RollingFileAppender.start(RollingFileAppender.java:79)
>>   at    at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:96)
>>   at    at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:315)
>>   at    at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:194)
>>   at    at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:180)
>>   at    at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:52)
>>   at    at ch.qos.logback.core.joran.spi.Interpreter.play(Interpreter.java:332)
>>   at    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:126)
>>   at    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:93)
>>   at    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:52)
>>   at    at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:77)
>>   at    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
>>   at    at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
>>   at    at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
>>   at    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
>>   at    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
>>   at    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
>>   at    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
>>   at    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
>>   at    at za.co.newco.common.ConfigTests.<init>(ConfigTests.java:16)
>>   at    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>   at    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>   at    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>   at    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>   at    at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:202)
>>   at    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:219)
>>   at    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
>>   at    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>   at    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
>>   at    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
>>   at    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>>   at    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>   at    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>   at    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>   at    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>   at    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>   at    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
>>   at    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
>>   at    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>   at    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
>>   at    at org.junit.runners.Suite.runChild(Suite.java:128)
>>   at    at org.junit.runners.Suite.runChild(Suite.java:24)
>>   at    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
>>   at    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
>>   at    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
>>   at    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
>>   at    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
>>   at    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
>>   at    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
>>   at    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:97)
>>   at    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:196)
>>   at    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
>>   at    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>   at    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>   at    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>   at    at java.lang.reflect.Method.invoke(Method.java:597)
>>   at    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
>> _______________________________________________
>> Logback-user mailing list
>> Logback-user at qos.ch
>> http://qos.ch/mailman/listinfo/logback-user
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://qos.ch/mailman/listinfo/logback-user


More information about the Logback-user mailing list