0
votes

Not sure what I am doing wrong here but my logging seems off. I am using

slf1.7.2 logback 1.0.9

Here is my config file:

<configuration debug="true">
    <contextName>myProduct</contextName>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>
    <appender name="ROLLINGFILE"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>../logs/myproduct.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>../logs/myproduct-%d{yyyy-DD}.%i.zip
            </fileNamePattern>
            <maxHistory>10</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>

            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} %-5level %logger{40} [%file:%line] -
                %msg%n</pattern>
        </encoder>
    </appender>
    <root>
        <appender-ref ref="ROLLINGFILE" />
    </root>
    <logger name="org.hibernate" level="error">
        <appender-ref ref="ROLLINGFILE" />
    </logger>
    <logger name="org.springframework" level="error">
        <appender-ref ref="ROLLINGFILE" />
    </logger>
    <logger name="com.edelweissco" level="error">
        <appender-ref ref="ROLLINGFILE" />
        <appender-ref ref="STDOUT" />
    </logger>
</configuration>

but when I deploy my application the logging is in the console even though I set the spring and hibernate to ERROR, the console is filled with their logging statements. My log file is not being created on the file system in any location, but I don't get an error.

Here is the console output when I start up:

21:28:34,276 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
21:28:34,276 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/Library/Tomcat/apache-tomcat-7.0.27/webapps/myapplication/WEB-INF/classes/logback-test.xml]
21:28:34,340 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [myProduct]
21:28:34,341 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
21:28:34,346 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
21:28:34,406 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
21:28:34,412 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ROLLINGFILE]
21:28:34,450 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use zip compression
21:28:34,454 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern ../logs/myproduct-%d{yyyy-DD}.%i for the active file
21:28:34,460 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@38a3c5b6 - The date pattern is 'yyyy-DD' from file name pattern '../logs/myproduct-%d{yyyy-DD}.%i.zip'.
21:28:34,460 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@38a3c5b6 - Roll-over at midnight.
21:28:34,460 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@38a3c5b6 - Setting initial period to Thu Jan 10 20:42:21 MST 2013
21:28:34,464 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
21:28:34,469 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ROLLINGFILE] - Active log file name: ../logs/myproduct.log
21:28:34,469 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ROLLINGFILE] - File property is set to [../logs/myproduct.log]
21:28:34,471 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ROLLINGFILE] to Logger[ROOT]
21:28:34,473 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate] to ERROR
21:28:34,474 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ROLLINGFILE] to Logger[org.hibernate]
21:28:34,474 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to ERROR
21:28:34,474 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ROLLINGFILE] to Logger[org.springframework]
21:28:34,474 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.edelweissco] to ERROR
21:28:34,474 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ROLLINGFILE] to Logger[com.edelweissco]
21:28:34,474 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[com.edelweissco]
21:28:34,475 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
21:28:34,477 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@6f92c766 - Registering current configuration as safe fallback point
Jan 12, 2013 9:28:34 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext

No errors in the output, but the logging doesn't seem like its using the config file right.

1
Chances are the user running the java process is not allowed to write in the log folder. Did you check it out ?Francois

1 Answers

1
votes

If you are using jboss5.1 and having the same problem, the add the following in your jboss-web.xml.

<class-loading>
    <loader-repository>
        com.hp:classloader=logback-slf4j
        <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
    </loader-repository>
</class-loading>

This should solve your issue.