1

我正在尝试让 LogBack 将 HSQLDB 与 C3P0 一起使用。鉴于我当前的环境,我目前坚持使用此配置。我对 Log4J 代码进行了大量投资,并且还需要使用 SLF4J Log4J 适配器。当我尝试一个简单的日志记录程序时,它卡在了记录器配置阶段。这是我的logback.xml

<configuration>
    <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
        <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
            <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
                <driverClass>org.hsqldb.jdbcDriver</driverClass>
                <jdbcUrl>jdbc:hsqldb:hsql://localhost:9001/mid_logs</jdbcUrl>
                <user>sa</user>
                <password>sa</password>
            </dataSource>
        </connectionSource>
    </appender>
    <root level="debug">
        <appender-ref ref="DB" />
    </root>
</configuration>

我的类路径是:

bin/.;lib/hsqldb.jar;lib/log4j-over-slf4j-1.5.8.jar;lib/logback-access-0.9.17.jar;lib/logback-classic-0.9.17.jar;lib/logback-core-0.9.17.jar;lib/slf4j-api-1.5.8.jar;lib/slf4j-log4j12-1.5.8.jar;lib/c3p0-0.9.1.2.jar

这是我的代码片段:

System.out.println("Starting");
Logger logger = Logger.getLogger(TestLogging.class);
System.out.println("got Logger");

“开始”出现在控制台输出中,但没有别的。

任何帮助,将不胜感激!

4

2 回答 2

0

What status messages are you getting? You can have them listed by adding the following line in your configuraton file:

<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />  

Since your configuration file above is not nicely formatted, making it hard to read.

于 2009-10-08T07:40:42.910 回答
0

我将其添加StatusListenerlogback.xml文件中,这是输出:

07:45:12,816 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.db.DBAppender]
07:45:12,832 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [DB]
07:45:12,848 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing component [connectionSource] on top of the object stack.
07:45:13,129 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing component [dataSource] on top of the object stack.

如果我执行“ netstat -a -n”,我会看到与数据库的连接,但没有活动。

于 2009-10-08T13:05:42.960 回答