New Maven dependcy打开jOOQ日志记录

时间:2016-03-23 07:24:09

标签: java maven logging pom.xml jooq

最近,我已经为项目添加了新的依赖项来生成.xls文件。

的pom.xml

    <dependency>
      <groupId>org.jxls</groupId>
      <artifactId>jxls</artifactId>
      <version>2.0.0</version>
    </dependency>
    <dependency>
      <groupId>org.jxls</groupId>
      <artifactId>jxls-poi</artifactId>
      <version>1.0.0</version>
    </dependency>

代码

 public StreamingOutput createStreamedExcelReport(Map<String, Object> params, String templateName, String[] columnsToHide) throws Exception {
        try(InputStream is = ReportGenerator.class.getResourceAsStream(templateName)) {
            assert is != null;
            final Transformer transformer = PoiTransformer.createTransformer(is);
            AreaBuilder areaBuilder = new XlsCommentAreaBuilder(transformer);
            List<Area> xlsAreaList = areaBuilder.build();
            Area xlsArea = xlsAreaList.get(0);
            Context context = new PoiContext();
            for(Map.Entry<String, Object> entry : params.entrySet()) {
                context.putVar(entry.getKey(), entry.getValue());
            }
            xlsArea.applyAt(new CellRef("Sheet1!A1"), context);
            xlsArea.processFormulas();
            return new StreamingOutput() {
                @Override
                public void write(OutputStream out) throws IOException {
                    ((PoiTransformer) transformer).getWorkbook().write(out);
                }
            };
        }
    }

不幸的是,它可能会启用jOOQ调试日志记录,这非常糟糕,因为它会记录所有数据库查询。应用程序正在对.xls进行大查询,因此它不应该记录(在3分钟内输出~1.5GB)。

日志示例

08:08:23.094 [http-bio-8080-exec-7] DEBUG org.jooq.tools.LoggerListener - Executing query          : select "XXXXXXXX"."XXX", "XXXXXXX"."XXXXXXX" from "XXXXX" where "XXXXX"."XXX" = ?
08:08:23.095 [http-bio-8080-exec-7] DEBUG org.jooq.tools.LoggerListener - -> with bind values      : select "XXXXXXXX"."XXX", "XXXXXXX"."XXXXXXX" from "XXXXX" where "XXXXX"."XXX" = 'XXXX.XXXXXXXXXXXXXXXXXXX'
08:08:23.098 [http-bio-8080-exec-7] DEBUG org.jooq.tools.StopWatch - Query executed           : Total: 4.17ms
08:08:23.099 [http-bio-8080-exec-7] DEBUG org.jooq.tools.LoggerListener - Fetched result           : +----------------------------------------+-----------+
08:08:23.100 [http-bio-8080-exec-7] DEBUG org.jooq.tools.LoggerListener -                          : |KEY                                     |VALUE      |
08:08:23.100 [http-bio-8080-exec-7] DEBUG org.jooq.tools.LoggerListener -                          : +----------------------------------------+-----------+
08:08:23.100 [http-bio-8080-exec-7] DEBUG org.jooq.tools.LoggerListener -                          : |xxxx.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|0 0 3 * * ?|
08:08:23.100 [http-bio-8080-exec-7] DEBUG org.jooq.tools.LoggerListener -                          : +----------------------------------------+-----------+
08:08:23.100 [http-bio-8080-exec-7] DEBUG org.jooq.tools.StopWatch - Finishing                : Total: 6.756ms, +2.586ms

2 个答案:

答案 0 :(得分:6)

通过记录配置彻底修复

默认情况下,jOOQ使用调试日志记录,通过它首先在类路径上发现的这三个日志框架中的任何一个:slf4j,log4j,java.util.logging。 jxls库通过slf4j as can be seen in its pom.xml依赖于logback:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.12</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>1.7.12</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>1.1.3</version>
</dependency>

为了关闭jOOQ调试日志记录,您应该相应地配置日志记录框架(in this case: logback)。

在jOOQ中快速修复:

您还可以通过指定:

直接关闭jOOQ中的大多数日志记录
Settings.withExecuteLogging(false);

有关详细信息,请参阅: http://www.jooq.org/doc/latest/manual/sql-execution/logging

答案 1 :(得分:0)

您可以在依赖项中使用exclusion以避免使用jooQ日志记录:

<dependency>
    <groupId>org.jxls</groupId>
    <artifactId>jxls</artifactId>
    <version>2.0.0</version>
    <exclusion>         
       <groupId>org.jooq</groupId>
       <artifactId>jooq</artifactId>
    </exclusion>
</dependency>
<dependency>
    <groupId>org.jxls</groupId>
    <artifactId>jxls-poi</artifactId>
    <version>1.0.0</version>
    <exclusion>         
       <groupId>org.jooq</groupId>
       <artifactId>jooq</artifactId>
    </exclusion>
</dependency>

注意:您可以从可能依赖于jOOQ日志记录的那个中排除。