Logback - C3P0 和 HSQLDB

发布于 2024-08-06 05:58:29 字数 1405 浏览 5 评论 0原文

我正在尝试让 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");

“Starting”出现在控制台输出中,但没有其他内容。

任何帮助将不胜感激!

I'm trying to get LogBack to use a HSQLDB with C3P0. I'm stuck with this configuration at the moment given my current environment. I have a large investment with Log4J code and will also need to use the SLF4J Log4J Adapter. When I try a simple logging program it's getting stuck in the logger configuration stage. Here is my 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>

My classpath is:

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

Here is a snippet of my code:

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

The 'Starting' appears in the console output, but nothing else.

Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝天白云 2024-08-13 05:58:29

您收到什么状态消息?您可以通过在配置文件中添加以下行来列出它们:

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

由于上面的配置文件格式不正确,因此难以阅读。

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.

挽梦忆笙歌 2024-08-13 05:58:29

我将 StatusListener 添加到 logback.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”,我会看到连接到数据库,但没有活动。

I added the StatusListener to the logback.xml file and here is the output:

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.

If I do a "netstat -a -n" I see connections to the database, but no activity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文