Hevan
Hevan

Reputation: 159

Configuration of logback failed -- Why

I havenot able to use logback.xml file even if I have put it in every source folder or use -Dlogback.configurationFile=C:\Users\dell\Documents\Corr\conf\logback.xml as program argument or vm argument. But, it didnot work. Why? Why?

Where should I put this file so that it will be detected?

What I have done;

logback.xml

<configuration> 
    <appender   name ="FileAppender"
        class="ch.qos.logback.core.FileAppender">


        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>         INFO    </level>
            <onMatch>       ACCEPT  </onMatch>
            <onMismatch>    DENY    </onMismatch>
        </filter>

        <property file="conf/variables.properties" />

        <file>  ${HOME}/build/log/corr.log  </file>
        <rollingPolicy  class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>   
                ${HOME}/build/log/%d{yyyy/MM/dd}.%i.log 
            </fileNamePattern>

            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>   2MB </maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>

        <encoder>
            <charset>UTF-8</charset>
            <pattern>
                %date{yyyy-MM-dd HH:mm:ss.SSS}
                %level{5}
                [%thread] 
                %class{0}.%method at %line 
                %msg
                %n
                %ex{full}
                %n
            </pattern>
        </encoder>
    </appender>

    <root   level="DEBUG">
            <appender-ref   ref="FileAppender" />
    </root>
</configuration>

property file; variables.properties

HOME=C:\Users\dell\Documents\Corr

project hierarchy

Corr
  | - - src
          | - - CorrAnaly
                   | - - main.java
  | - - testSrc
  | - - build
          | - - log
  | - - bin
  | - - conf
          | - - logback.xml
          | - - variables.properties

Where I have put logback.xml

All of them have not worked. Also, I have tried to use conf folder as source folder. I have declared it as so and used it but not worked.

Help me to figure out why logback not detect my file. What should I do so as to use Logback feature?

Environment: Windows 7, Eclipse Indigo

UPDATE

To Run application, I am using;

my ivy.xml file

<ivy-module version="2.0">
    <configurations defaultconfmapping="runtime->compile">      
        <conf   name="compile" />
        <conf   name="test" />
        <conf   name="runtime"      
                extends="compile"   />
    </configurations>
    <dependencies>          
        <dependency org="SLF4J" name="slf4j-api-1.7.7"  rev="1.7.7"
                            conf="compile->default"/>   
        <dependency org="LOGBack"   name="logback-core-1.1.2"   rev="1.1.2" 
                            conf="runtime->default"/>
        <dependency org="SLF4J" name="slf4j-jdk14-1.7.7"    rev="1.7.7" 
                            conf="runtime->default"/>
    </dependencies>
</ivy-module>

UPDATE 2 I have also tried with simple logback.xml in case of my first configuration is not working. It didnot worked even for simple logback.xml case;

<appender   name ="ConsoleAppender" 
    class="ch.qos.logback.core.ConsoleAppender">

    <encoder>   
        <charset>   UTF-8   </charset>
        <pattern>%-5level [%thread] %class{0}.%method at line %line --%message%n%ex</pattern>
    </encoder>
</appender>

<root   level="DEBUG">
        <appender-ref   ref="ConsoleAppender" />
</root>

UPDATE 3

Since last night, I have tried bunch of things and lastly in source code, I can get not null result from getClass().getResource("/logback/logback.xml").toURI().toString(). However, still, default logback.xml is called.

bin structure

bin
 | - - Corr
 | - - conf
         | - - logback.xml

I have tried -Dlogback.configurationFile= in vm argument section of Eclipse ( separatly and one by one);

My brain: Out of mind Error; Help me!

Upvotes: 2

Views: 2584

Answers (1)

Hevan
Hevan

Reputation: 159

I donot know the reason behind above problem but after changing dependency file like;

<dependency org="SLF4J" name="slf4j-api-1.7.7"  rev="1.7.7"
            conf="compile->default"/>
<dependency org="LOGBack"   name="logback-core-1.1.2"   rev="1.1.2" 
            conf="runtime->default"/>
<dependency org="LOGBack"   name="logback-classic-1.1.2"    rev="1.1.2" 
            conf="runtime->default"/>

configuration file of mine has, now, recognized by Logback. I think slf4j-jdk14-1.7.7 blocking Logback to read my configuration file.

To emphasize, I have used jdk of slf4j which caused to bind Logback to its internal and to ignore my own configuration file namely logback.xml. (I said "ignores" because you can my effort, all possibilities I have tried, at question body.)

Upvotes: 1

Related Questions