English 中文(简体)
JBoss 7 + 休眠+ Log4j
原标题:JBoss 7 + Hibernate + Log4j

我设置了我的 Java EE 6 应用程序, 以 Jboss 7. 1 中的log4j 快速启动为起点。

我的关键 pom.xml 补充是:

<dependencyManagement>
        <dependencies>
            <!-- Define Log4j dependency and its version -->
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${log4j.version}</version>
            </dependency>
...
        </dependencies>
    </dependencyManagement>

<dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <scope>provided</scope>
        </dependency>

版本为1.2.16。

现在我可以做:

private static final Logger logger = Logger.getLogger(MacchinarioController.class);

并按预期使用登录器 很好!

我没有log4j.xml 或. property 文件。

现在我要休眠在控制台打印所有正在执行的 SQL 语句, < 坚固 > 包括参数值

我创建了这个log4j.xml, 并将其放入 src/main/ resources 源文件夹 :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Threshold" value="info"/>
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} [%t] %-5p %c{1} - %m%n"/>
        </layout>
    </appender>

    <appender name="rolling-file" class="org.apache.log4j.RollingFileAppender">
        <param name="file" value="Program-Name.log"/>
        <param name="MaxFileSize" value="1000KB"/>
        <param name="MaxBackupIndex" value="4"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %l - %m%n"/>
        </layout>
    </appender>
    <logger name="org.hibernate">
        <level value="ALL" />
    </logger>

    <root>
        <priority value ="debug" />
        <appender-ref ref="console" />
        <appender-ref ref="rolling-file" />
    </root>
</log4j:configuration>

但什么也没有出现, 我哪里做错了?

最佳回答

您是否正在使用 < a href=" "https://docs.jboss.org/ authers/display/ AS71/ how+To# Howto- HowdoIuselog4j. propertertysorlog4j.xmlin 继续使用博客子系统配置% 3F" rel=“nofollow”>jbos- impreport- struit.xml 来排除log4j 的服务器版本?

如果您从头开始一个应用程序, 我绝对不会选择log4j。 我偏向于 JBos 登录, 但JBos 登录、 slf4j 或回溯比log4j 更好 。

默认 JBoss AS 7 使用 JBoss 登录与 JBoss 日志管理器连接。 尽管您可以/ 可以使用 JBoss 日志管理器, 因为它会和任何日志管理器一起工作 。

如果您想要使用log4j, 请不要使用log4j配置。 将logger/ 类别添加到登录子系统, 以查看您正在寻找的结果 。

所有这一切都说,在JBos AS 7 的下一期版本中,将会找到您的log4j配置, 并且会以您预期的方式为您工作。 这些更改已被推到 < a href=" https://github.com/jbossas/jboss-as/commit/6da8615881b86c8c8cde2cd2d1d3d841888a674666f07e" rel=“ no follow”>上流。

问题回答

暂无回答




相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签