2

I want lo log hibernate generated sql queries using logback logging framework, but problem is that it is generating log file but not logging anything related to hibernate.

This is how logback.xml looks like

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${Project_HOME}\\module\\logs\\module.log</file>
        <append>true</append>
        <rollingPolicy     class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${Project_HOME}\\module\\logs\\module_%d{yyyy-    MM-dd}.%i.log.zip
            </fileNamePattern>
            <maxHistory>10</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10KB</maxFileSize>

            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>%date %-5level [%file:%line] - %msg%n
            </pattern>
        </encoder>
    </appender>
<logger name="org.hibernate.SQL">
        <level value="DEBUG" />
        <appender-ref ref="FILE" />
    </logger>

Also all other logging using same appender is working fine.

2 Answers 2

2

I would suggest you to add a property in hibernate-cfg.xml

<property name="show_sql">true</property>

Hope this will help you .

Sign up to request clarification or add additional context in comments.

1 Comment

Show_sql will always log to System.out()
1

I would recommend you change your logger config a little:

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

2 Comments

@jaishukla: It should work, specially if it works for your other classes. Could you please upload a part of the log file?
@jaishukla: are you sure that you're calling hibernate from your code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.