jOOQ 3.1打印日志,但jOOQ 3.4没有

时间:2014-07-09 07:45:02

标签: spring tomcat log4j jooq

我的项目中有一个奇怪的问题(Spring,log4j,maven,jOOQ)。该项目是一个多罐子,父母和所有儿童项目共享的共同poms。

问题

如果我在其中一个子项目中使用jOOQ 3.1 ,则会创建滚动文件并使用所有日志进行更新。如果我使用jOOQ 3.4 重新编译项目(jar是普通pom项目的依赖项),我的滚动文件没有创建,我也没有得到任何日志。

为什么我从3.1升级到3.4?因为我得到this error

我的 log4j.properties 文件如下:

log4j.rootCategory=DEBUG, stdout, rollingFile

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t %c] - %m%n

log4j.appender.stdout.layout.ConversionPattern=%p [%c{3}] %m%n

log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=${catalina.base}/logs/my_file.log
log4j.appender.rollingFile.layout.ConversionPattern=%5p %d{dd MMM yyyy HH:mm:ss} [%c] - %m%n
log4j.appender.rollingFile.Append=true
log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingFile.DatePattern='.'yyyy-MM-dd
log4j.appender.rollingFile.MaxFileSize=10MB
log4j.appender.rollingFile.MaxBackupIndex=99

我无法想到jOOQ版本与打印/不打印日志之间的关系,尤其是the jOOQ documentation表明它很容易记录。所以这就是为什么我要问你们。

请不要犹豫,询问更多细节。

谢谢大家!

更新1 - Pom来源

这些都是有关的poms(一些细节因为显而易见的原因而被修改)

super_parent_module

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>my_group_id</groupId>
    <artifactId>super_parent_module</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>name</name>
    <description>description</description>
    <url>http://maven.apache.org</url>

    <scm>
        <developerConnection>XXXXX</developerConnection>
    </scm>

    <distributionManagement>
       <!-- repository -->
    </distributionManagement>

    <profiles>
        <!-- profiles -->
    </profiles>

    <properties>
        <deployment.local.directory>XXXXX</deployment.local.directory>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <configLocation>XXXXXXX</configLocation>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>**/generated/**</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
            </plugin>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-release-plugin</artifactId>
               <version>2.4.2</version>
               <configuration>
                  <tagNameFormat>v@{project.version}</tagNameFormat>
                  <autoVersionSubmodules>true</autoVersionSubmodules>
                  <releaseProfiles>releases</releaseProfiles>
                  <remoteTagging>true</remoteTagging>
                  <tagBase>XXXXXXXX</tagBase>
               </configuration>
            </plugin>
        </plugins>
    </build>


</project>

super_common_module

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent> 
        <groupId>my_group_id</groupId>  
        <artifactId>super_parent_module</artifactId>
        <version>1.0.1-SNAPSHOT</version>
        <relativePath />
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>super_common_module</artifactId>
    <version>1.0.10-SNAPSHOT</version>
    <name>name</name>
    <url>http://maven.apache.org</url>

    <scm>
        <developerConnection>XXXXXX</developerConnection>
    </scm>

    <dependencies>
        <dependency>
            <!-- guava 15 -->
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>3.2.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>args4j</groupId>
            <artifactId>args4j</artifactId>
            <version>2.0.26</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ojdbc</groupId>
            <artifactId>ojdbc</artifactId>
            <version>14</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${project.build.sourceDirectory}</directory>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                  <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                  <resource>META-INF/spring.schemas</resource>
                                </transformer>
                            </transformers>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>with-deps</shadedClassifierName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </build>

</project>

parent_module

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent> 
        <groupId>my_group_id</groupId>  
        <artifactId>super_parent_module</artifactId>
        <version>1.0.1-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <groupId>my_group_id.client</groupId>
    <artifactId>parent_module</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>parent_module</name>
    <description>description</description>
    <url>http://maven.apache.org</url>

    <scm>
        <developerConnection>XXXXXX</developerConnection>
    </scm>

    <modules>
        <module>common_module</module>
        <module>my_problematic_module</module>
        <module>other_module</module>
        <module>other_module</module>       
    </modules>

    <profiles>
        <!-- profiles -->
    </profiles>

    <properties>
        <springws.version>2.1.3.RELEASE</springws.version>
        <spring.version>3.2.4.RELEASE</spring.version>
        <jooq.version>3.4.0</jooq.version>
        <jooq-codegen.url>XXXXX</jooq-codegen.url>
        <jooq-codegen.user>XXXXX</jooq-codegen.user>
        <jooq-codegen.password>XXXX</jooq-codegen.password>
    </properties>

    <dependencies>
        <dependency>
            <groupId>my_group_id</groupId>
            <artifactId>super_common_module</artifactId>
            <version>1.0.10-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

common_module

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent> 
        <groupId>my_group_id.client</groupId>  
        <artifactId>parent_module</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>common_module</artifactId>
    <description>description</description>
    <packaging>jar</packaging>

    <name>name</name>
    <url>http://maven.apache.org</url>

    <dependencies>

        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen-maven</artifactId>
            <version>${jooq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>${jooq.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>${jooq.version}</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <!-- jOOQ configuration -->
            <plugin>
                <groupId>org.jooq</groupId>
                <artifactId>jooq-codegen-maven</artifactId>
                <version>${jooq.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>ojdbc</groupId>
                        <artifactId>ojdbc</artifactId>
                        <version>14</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.xml.bind</groupId>
                        <artifactId>jaxb-api</artifactId>
                        <version>2.2.6</version>
                    </dependency>
                    <dependency>
                        <groupId>my_group_id</groupId>
                        <artifactId>jooq-ext</artifactId>
                        <version>1.0.3-SNAPSHOT</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <jdbc>
                        <driver>oracle.jdbc.OracleDriver</driver>
                        <url>${jooq-codegen.url}</url>
                        <user>${jooq-codegen.user}</user>
                        <password>${jooq-codegen.password}</password>
                    </jdbc>
                    <generator>
                        <name>org.jooq.util.MyGenerator</name>
                        <database>
                            <name>org.jooq.util.oracle.OracleDatabase</name>
                            <includes>tables and packages</includes>
                            <excludes />
                            <inputSchema>my_schema</inputSchema>
                        </database>
                        <generate>
                            <relations>true</relations>
                            <deprecated>false</deprecated>
                            <instanceFields>true</instanceFields>
                            <generatedAnnotation>false</generatedAnnotation>
                            <records>true</records>
                            <pojos>false</pojos>
                            <immutablePojos>false</immutablePojos>
                            <interfaces>false</interfaces>
                            <daos>false</daos>
                            <jpaAnnotations>false</jpaAnnotations>
                            <validationAnnotations>false</validationAnnotations>
                            <globalObjectReferences>false</globalObjectReferences>
                        </generate>
                        <target>
                            <packageName>my_group_id.model.generated</packageName>
                            <directory>${project.build.directory}/generated-xxxxx/jooq</directory>
                        </target>
                    </generator>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

my_problematic_module

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>my_group_id.client</groupId>
        <artifactId>parent_module</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>my_problematic_module</artifactId>
    <packaging>war</packaging>
    <name>name</name>
    <description>description</description>
    <url>http://www.springframework.org/spring-ws</url>

    <profiles>
        <!-- profiles... -->
    </profiles>

    <scm>
        <connection>XXXXXX</connection>
    </scm>

    <build>
        <finalName>${project.artifactId}-${project.version}-${lane}</finalName>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>   
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <attachClasses>true</attachClasses>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat6-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <url>http://localhost:8084/manager</url>
                    <server>mytomcat</server>
                    <path>/project_path</path>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jax-ws-commons</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>2.3</version>
                <dependencies>
                    <dependency>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.5</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>exec_id</id>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                            <target>2.0</target>
                            <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
                            <wsdlFiles>
                                <wsdlFile>exec_id.wsdl</wsdlFile>
                            </wsdlFiles>
                            <extension>true</extension>
                            <xjcArgs>
                                <!-- xjcArg>some args</xjcArg -->
                            </xjcArgs>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- another execution -->
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>XXXXX</exclude>
                            <exclude>**/generated/**</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>common_module</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-test</artifactId>
            <version>${springws.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-basics</artifactId>
            <version>0.6.5</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>XXXXX</exclude>
                            <exclude>**/generated/**</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

</project>

2 个答案:

答案 0 :(得分:1)

我找到了解决方案:

我注意到jooq-codegen-maven-3.4.0.jar有一个log4j.xml,而jooq-codegen-maven-3.1.0.jar没有。

然后我创建了一个log4j.xml文件来替换我的log4j.properties并且rollingFile又开始写了!

我相信log4j在jooq-codegen-maven-3.4.0.jar中使用xml版本(仅在控制台中写入)而不是我的log4j.properties。也许有办法告诉log4j哪个文件有更多优先级,但显然创建这个其他log4j.xml已经覆盖了jooq。

@LukasEder,你认为这应该在jooq中得到解决吗?

由于

答案 1 :(得分:0)

您好像错过了pom.xml文件中的log4j依赖项。 jOOQ试图找到对类路径的依赖,但你还没有添加它(至少不在该模块中)。

尝试添加

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

(很奇怪这在jOOQ 3.4之前会有效)