简体   繁体   中英

Log4j not writing logs to database

I need to log errors for my application to database. I added the following in log4j.xml Database logs are not getting written to tables, but I could see log messages on my console.

What could be the reason for this. My database connect string details are correct.

log4j.xml

  <appender name="jdbcAppender" class="org.apache.log4j.jdbc.JDBCAppender"> 
        <param name="URL" value="jdbc:oracle:thin:@host:1521:test" /> 
        <param name="Driver" value="oracle.jdbc.driver.OracleDriver" /> 
        <param name="User" value="scott" /> 
        <param name="Password" value="tiger" /> 
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" 
              value="INSERT INTO my_table (log_date, log_level, location, message) VALUES ( '%d{ISO8601}','%p',
              '%C;%L', '%m' )" 
            /> 
        </layout> 
    </appender> 
    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"> 
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" 
              value="%d{ISO8601} %p (%C;%L) %m%n" 
            /> 
        </layout> 
    </appender> 
    <logger name="logging.simple.jdbcLogger" additivity="true">
        <level value="info"/> 
        <appender-ref ref="jdbcAppender"/> 
    </logger> 
    <root> 
        <level value="info"/> 
        <appender-ref ref="STDOUT"/> 
    </root> 
</log4j:configuration>

You'll see log messages on the console because you've sent all log messages to the console, but only loggers under the hierarchy of logging.simple.jdbcLogger are sent to jdbcAppender .

Do you see logging.simple.jdbcLogger messages on the console?

<appender-ref ref="jdbcAppender"/><root>...</root>部分。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM