如何避免slf4j日志中的多个日志文件?

时间:2015-06-23 13:18:35

标签: java spring logging slf4j

我正在使用logback.xml实现SLF4J日志记录,但应用程序正在创建多个日志文件。 我需要为日期创建一个日志文件,其中所有日志级别都在相同的日志文件中。

下面是我的logback.xml配置。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="LOG_FILE_LOCATION" value="./log/" />

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>[%d{yyyy-MM-dd HH:mm:ss}] [%thread] [%-5level] [%logger] - %msg%n</Pattern>
        </layout>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>[%d{yyyy-MM-dd HH:mm:ss}] [%thread] [%-5level] [%logger] - %msg%n</pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_FILE_LOCATION}/manageng_%d{yyyy-MM-dd_HH-mm-ss}.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>


    <appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>[%d{yyyy-MM-dd HH:mm:ss}] [%thread] [%-5level] [%logger] - %msg%n</Pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_FILE_LOCATION}/manageng_error_%d{yyyy-MM-dd_HH-mm-ss}.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>


    <logger name="net.indecomm.manageng" level="debug" additivity="false">
        <appender-ref ref="FILE"/>
        <appender-ref ref="CONSOLE"/>
    </logger>

    <root level="ERROR">
        <appender-ref ref="FILE-ERROR"/>
        <appender-ref ref="CONSOLE"/>
    </root>


</configuration>

1 个答案:

答案 0 :(得分:0)

将其简化为:

----------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                          | Name                  | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
----------------------------------------------------------------------------------------------------------------------------------------------------------
|   1 |  SORT AGGREGATE                    |                       |    257K|      1 |    257K|00:00:27.81 |    2153K|      1 |       |       |          |
|*  2 |   TABLE ACCESS BY INDEX ROWID      | ABM_BILL_DETAIL       |    257K|      1 |    366K|00:00:24.27 |    2153K|      1 |       |       |          |
|   3 |    NESTED LOOPS                    |                       |    257K|      1 |   4369K|00:01:44.38 |    1694K|      1 |       |       |          |
|*  4 |     TABLE ACCESS BY INDEX ROWID    | CV_PTAX_OUTSTANDING   |    257K|      1 |    380K|00:00:06.82 |     924K|      1 |       |       |          |
|*  5 |      INDEX RANGE SCAN              | INDX_BILLID_PO        |    257K|      1 |    408K|00:00:03.75 |     516K|      0 |       |       |          |
|*  6 |     INDEX RANGE SCAN               | INDX_ABD_BD_BILL_ID   |    380K|      1 |   3730K|00:00:03.91 |     770K|      0 |       |       |          |
|   7 |    SORT AGGREGATE                  |                       |   1679K|      1 |   1679K|00:00:57.53 |    5261K|      0 |       |       |          |
|*  8 |     TABLE ACCESS BY INDEX ROWID    | CV_BILL_DETAIL        |   1679K|      1 |   1646K|00:00:52.02 |    5261K|      0 |       |       |          |
|*  9 |      INDEX RANGE SCAN              | INDX_BILL_MAS_ID      |   1679K|     11 |     16M|00:00:18.16 |    3397K|      0 |       |       |          |
|  10 |      SORT AGGREGATE                |                       |    257K|      1 |    257K|00:36:19.20 |    4528K|    414K|       |       |          |
|* 11 |       TABLE ACCESS BY INDEX ROWID  | ABM_BILL_DETAIL       |    257K|      1 |    366K|00:36:14.84 |    4528K|    414K|       |       |          |
|  12 |        NESTED LOOPS                |                       |    257K|      1 |   4369K|05:15:33.92 |    4069K|    292K|       |       |          |
|* 13 |         TABLE ACCESS BY INDEX ROWID| CV_PTAX_OUTSTANDING   |    257K|      1 |    380K|00:14:31.47 |    3299K|    196K|       |       |          |
|* 14 |          INDEX RANGE SCAN          | INDX_BILLID_PO        |    257K|      1 |    408K|00:04:58.24 |    2140K|  86191 |       |       |          |
|* 15 |         INDEX RANGE SCAN           | INDX_ABD_BD_BILL_ID   |    380K|      1 |   3730K|00:10:32.73 |     770K|  95900 |       |       |          |
|  16 |        SORT AGGREGATE              |                       |   1679K|      1 |   1679K|00:32:25.01 |    5262K|    571K|       |       |          |
|* 17 |         TABLE ACCESS BY INDEX ROWID| CV_BILL_DETAIL        |   1679K|      1 |   1646K|00:32:18.54 |    5262K|    571K|       |       |          |
|* 18 |          INDEX RANGE SCAN          | INDX_BILL_MAS_ID      |   1679K|     11 |     16M|00:08:35.52 |    3398K|    135K|       |       |          |
|  19 |  HASH GROUP BY                     |                       |      1 |   1607K|    680K|00:00:37.33 |      17M|   1251K|   106M|  7852K|  127M (0)|
|  20 |   VIEW                             |                       |      1 |   1607K|   1941K|00:00:30.86 |      17M|   1251K|       |       |          |
|  21 |    HASH GROUP BY                   |                       |      1 |   1607K|   1941K|00:00:28.92 |      17M|   1251K|   283M|    15M|  283M (0)|
|  22 |     VIEW                           |                       |      1 |   1607K|   1941K|00:00:22.40 |      17M|   1251K|       |       |          |
|  23 |      HASH GROUP BY                 |                       |      1 |   1607K|   1941K|00:00:16.57 |      17M|   1251K|   295M|    15M|  301M (0)|
|* 24 |       HASH JOIN                    |                       |      1 |   1607K|   1941K|00:01:10.72 |     314K|    266K|  1011K|  1011K| 1231K (0)|
|  25 |        TABLE ACCESS FULL           | CV_FUND_COLLECTION    |      1 |     30 |     32 |00:00:00.02 |       3 |      2 |       |       |          |
|* 26 |        HASH JOIN                   |                       |      1 |   1607K|   1941K|00:01:06.82 |     314K|    266K|    39M|  4846K|   53M (0)|
|* 27 |         TABLE ACCESS FULL          | CV_RECEIPT_MASTER     |      1 |    657K|    669K|00:00:00.01 |    9176 |      0 |       |       |          |
|* 28 |         HASH JOIN                  |                       |      1 |   1861K|   1941K|00:01:05.64 |     305K|    266K|    16M|  2506K|   24M (0)|
|* 29 |          TABLE ACCESS FULL         | CV_ASSESSMENT         |      1 |    310K|    309K|00:00:00.31 |    6027 |      0 |       |       |          |
|* 30 |          HASH JOIN                 |                       |      1 |   1861K|   1941K|00:00:59.14 |     299K|    266K|    67M|  6159K|  103M (0)|
|* 31 |           TABLE ACCESS FULL        | CV_RECEIPT_TAX_DETAIL |      1 |   1859K|   1942K|00:00:29.15 |     268K|    266K|       |       |          |
|* 32 |           TABLE ACCESS FULL        | CV_RECEIPT_SAC_DETAIL |      1 |   1822K|   1951K|00:00:07.81 |   30755 |     28 |       |       |          |
----------------------------------------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter(("BD"."BD_TAXHEAD_ID"=7 AND "BD"."ISDELETED"='N'))
   4 - filter((SUBSTR("B"."BILL_CODE",1,6)=SUBSTR("B"."BILL_CODE",1,6) AND "B"."STATUS"='A'))
   5 - access("B"."BILL_ID"=:B1)
   6 - access("B"."BILL_ID"="BD"."BD_BILL_ID")
       filter("BD"."BD_BILL_ID"=:B1)
   8 - filter(("BDD"."TAX_ID"=7 AND "BDD"."STATUS"='A'))
   9 - access("BDD"."BILL_MAS_ID"=:B1)
  11 - filter(("BD"."BD_TAXHEAD_ID"=8 AND "BD"."ISDELETED"='N'))
  13 - filter((SUBSTR("B"."BILL_CODE",1,6)=SUBSTR("B"."BILL_CODE",1,6) AND "B"."STATUS"='A'))
  14 - access("B"."BILL_ID"=:B1)
  15 - access("B"."BILL_ID"="BD"."BD_BILL_ID")
       filter("BD"."BD_BILL_ID"=:B1)
  17 - filter(("BDD"."TAX_ID"=8 AND "BDD"."STATUS"='A'))
  18 - access("BDD"."BILL_MAS_ID"=:B1)
  24 - access("CFC"."FC_RRLOC_ID"="A"."WARD_ID")
  26 - access("RR"."RCT_ID"="SC"."RCT_ID")
  27 - filter("RR"."STATUS"='A')
  28 - access("SC"."CVP_ID"=TO_NUMBER("A"."CVP_ID"))
  29 - filter(("A"."STATUS"='A' OR "A"."STATUS"='O'))
  30 - access("CRTD"."RCT_DET_ID"="SC"."RCPT_DET_ID")
  31 - filter(("CRTD"."TAX_ID"=14 AND "CRTD"."STATUS"='A'))
  32 - filter("SC"."STATUS"='A')