2016-11-29 9 views
2

c3po журналы обычно печатаются консолью. Я попытался ВПЕРЕД C3PO лога в файл, но не позволяетВперед c3po войти в файл при регистрации

вот мой logback.xml и pom.xml

Logback

<?xml version="1.0" encoding="UTF-8" ?> 
<configuration scanPeriod="10 seconds" debug="false" scan="true"> 
    <property name="LOG_DIR" value="logs" /> 
    <appender name="STDOUTAppender" class="ch.qos.logback.core.ConsoleAppender"> 
     <encoder> 
      <pattern>%date %level [%X{traceid}] - %C{1}:%L %msg%n</pattern> 
     </encoder> 
    </appender> 


    <appender name="SPRING" 
     class="ch.qos.logback.core.rolling.RollingFileAppender"> 
     <File>${LOG_DIR}/spring.log</File> 
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
      <FileNamePattern>${LOG_DIR}/spring.log.%d{yyyy-MM-dd-HH} 
      </FileNamePattern> 

      <MaxHistory>30</MaxHistory> 
     </rollingPolicy> 

     <encoder> 
      <pattern>%date %level [%X{traceid}] - %C{1}:%L %msg%n</pattern> 
     </encoder> 
    </appender> 

    <appender name="errorAppender" 
     class="ch.qos.logback.core.rolling.RollingFileAppender"> 
     <File>${LOG_DIR}/error/ERROR.log</File> 
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
      <FileNamePattern>${LOG_DIR}/error/ERROR.log.%d{yyyy-MM-dd-HH} 
      </FileNamePattern> 

      <MaxHistory>72</MaxHistory> 
     </rollingPolicy> 

     <encoder> 
      <pattern>%date %level [%thread] %msg%n</pattern> 
     </encoder> 

     <filter class="ch.qos.logback.classic.filter.LevelFilter"> 
      <level>ERROR</level> 
      <onMatch>ACCEPT</onMatch> 
      <onMismatch>DENY</onMismatch> 
     </filter> 
    </appender> 

    <appender name="AppAppender" 
     class="ch.qos.logback.core.rolling.RollingFileAppender"> 
     <File>${LOG_DIR}/application/APPLICATION.log</File> 
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
      <FileNamePattern>${LOG_DIR}/application/APPLICATION.log.%d{yyyy-MM-dd-HH} 
      </FileNamePattern> 
     </rollingPolicy> 

     <encoder> 
      <pattern>%date %level [%X{traceid}] - %C{1}:%L %msg%n</pattern> 
     </encoder> 
    </appender> 

    <appender name="TxnAppender" 
     class="ch.qos.logback.core.rolling.RollingFileAppender"> 
     <File>${LOG_DIR}/txn/TXN.log</File> 
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
      <FileNamePattern>${LOG_DIR}/txn/TXN.log.%d{yyyy-MM-dd-HH} 
      </FileNamePattern> 
     </rollingPolicy> 

     <encoder> 
      <pattern>%msg%n</pattern> 
     </encoder> 
    </appender> 

    <appender name="AlarmAppender" 
     class="ch.qos.logback.core.rolling.RollingFileAppender"> 
     <File>${LOG_DIR}/alarm/ALARM.log</File> 
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
      <FileNamePattern>${LOG_DIR}/alarm/ALARM.log.%d{yyyy-MM-dd} 
      </FileNamePattern> 
     </rollingPolicy> 

     <encoder> 
      <pattern>%msg%n</pattern> 
     </encoder> 
    </appender> 

    <appender name="C3POAppender" 
     class="ch.qos.logback.core.rolling.RollingFileAppender"> 
     <File>${LOG_DIR}/c3po/c3po.log</File> 
     <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
      <FileNamePattern>${LOG_DIR}/c3po/c3po.log.%d{yyyy-MM-dd} 
      </FileNamePattern> 

      <MaxHistory>30</MaxHistory> 
     </rollingPolicy> 

     <encoder> 
      <pattern>%msg%n</pattern> 
     </encoder> 
    </appender> 

    <logger name="org.springframework"> 
     <level value="INFO" /> 
     <appender-ref ref="SPRING" /> 
    </logger> 

    <logger name="TxnLogger"> 
     <level value="INFO" /> 
     <appender-ref ref="TxnAppender" /> 
    </logger> 

    <logger name="AlarmLogger"> 
     <level value="INFO" /> 
     <appender-ref ref="AlarmAppender" /> 
    </logger> 

    <logger name="com.mchange.v2.c3p0"> 
     <appender-ref ref="C3POAppender" /> 
    </logger> 

    <logger name="com.ttech.pnsender" additivity="true" level="DEBUG"> 
     <appender-ref ref="AppAppender" /> 
     <appender-ref ref="errorAppender" /> 
    </logger> 

    <root level="ERROR"> 
     <appender-ref ref="STDOUTAppender" /> 
    </root> 
</configuration> 

pom.xml

<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>com.ahmetk</groupId> 
<artifactId>pnsender</artifactId> 
<version>1.0.1</version> 
<packaging>jar</packaging> 
<name>pnsender</name> 

<developers> 
    <developer> 
     <id>TTAHKARAKAYA</id> 
     <name>Ahmet Karakaya</name> 
     <email>[email protected]</email> 
     <organization>Turkcell Teknoloji</organization> 
     <organizationUrl>http://www.turkcellteknoloji.com.tr/</organizationUrl> 
     <roles> 
      <role>developer</role> 
     </roles> 
    </developer> 
</developers> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <java.version>1.8</java.version> 
    <docker.image.prefix>springio</docker.image.prefix> 
</properties> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.4.2.RELEASE</version> 
</parent> 

<build> 

    <plugins> 

     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 




    </plugins> 



</build> 

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>redis.clients</groupId> 
     <artifactId>jedis</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-autoconfigure</artifactId> 
    </dependency> 

    <!-- weblogic üzerine deploy etmek için websocket collision olmasin. --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>org.apache.tomcat.embed</groupId> 
       <artifactId>tomcat-embed-websocket</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
org.apache.tomcat.embed tomcat-embed-webs ocket при условии ->
<!-- to ensure that the embedded servlet container doesn’t interfere with the servlet container --> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-tomcat</artifactId> 
    <scope>provided</scope> 
</dependency> 


    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jdbc</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>javax.ws.rs</groupId> 
     <artifactId>javax.ws.rs-api</artifactId> 
     <version>2.0.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-all</artifactId> 
     <version>1.9.5</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>com.oracle</groupId> 
     <artifactId>ojdbc6</artifactId> 
     <version>11.2.0.4</version> 
    </dependency> 
    <dependency> 
     <groupId>com.mchange</groupId> 
     <artifactId>c3p0</artifactId> 
     <version>0.9.2.1</version> 
    </dependency> 

    <dependency> 
     <groupId>com.googlecode.libphonenumber</groupId> 
     <artifactId>libphonenumber</artifactId> 
     <version>7.2.6</version> 
    </dependency> 

    <dependency> 
     <groupId>com.google.code.gson</groupId> 
     <artifactId>gson</artifactId> 
     <version>2.4</version> 
    </dependency> 

    <dependency> 
     <groupId>com.google.guava</groupId> 
     <artifactId>guava</artifactId> 
     <version>19.0</version> 
    </dependency> 

    <dependency> 
     <groupId>com.datastax.cassandra</groupId> 
     <artifactId>cassandra-driver-core</artifactId> 
     <version>3.1.0</version> 
    </dependency> 

    <dependency> 
     <groupId>com.datastax.cassandra</groupId> 
     <artifactId>cassandra-driver-mapping</artifactId> 
     <version>3.1.0</version> 
    </dependency> 

    <dependency> 
     <groupId>com.googlecode.json-simple</groupId> 
     <artifactId>json-simple</artifactId> 
     <version>1.1.1</version> 
    </dependency> 


    <!-- Push Notification API for IOS devices --> 
    <dependency> 
     <groupId>com.notnoop.apns</groupId> 
     <artifactId>apns</artifactId> 
     <version>1.0.0.Beta7_2-SNAPSHOT</version> 
     <exclusions> 
      <exclusion> 
       <groupId>com.fasterxml.jackson.core</groupId> 
       <artifactId>jackson-databind</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 


    <dependency> 
     <groupId>com.relayrides</groupId> 
     <artifactId>pushy</artifactId> 
     <version>0.5-SNAPSHOT</version> 
    </dependency> 

    <!-- KAFKA-QUEUE --> 
    <dependency> 
     <groupId>org.apache.kafka</groupId> 
     <artifactId>kafka_2.10</artifactId> 
     <version>0.8.2.1</version> 
      <exclusions> 
      <exclusion> 
       <groupId>org.slf4j</groupId> 
       <artifactId>slf4j-log4j12</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.kafka</groupId> 
     <artifactId>kafka-clients</artifactId> 
     <version>0.8.2.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.avro</groupId> 
     <artifactId>avro</artifactId> 
     <version>1.7.7</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-actuator</artifactId> 
    </dependency> 

<!--weblogic deployment 3.2.1 ile çalıştı --> 
<dependency> 
    <groupId>org.jboss.logging</groupId> 
    <artifactId>jboss-logging</artifactId> 
    <version>3.3.0.Final</version> 
</dependency> 

    <!-- TESTING- EMBEDEED DB --> 
    <dependency> 
     <groupId>hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
     <version>1.8.0.10</version> 
     <scope>test</scope> 
    </dependency> 

</dependencies> 

+1

Есть ли в папке $ {LOG_DIR}/c3po какие-либо разрешения? – kuhajeyan

+0

nope, другой appender работает правильно, даже создается файл c3po/c3po.log, –

+0

не может переслать журнал в файл, на данный момент я просто отключил c3p0 logging temporarly com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL –

ответ

1

я получил подобный вопрос при использовании SLF4J + Logback + C3P0 комбинацию.

Найдено решение как ниже шаги:

  1. Пусть c3p0 (Mlog) выбрать java 1.4+ standard logging, никаких действий не требуется для этого. Automaticly выбирает `, если вы не настроить FallbackMLog
  2. Добавить зависимость org.slf4j/jul-to-slf4j к вашему pom.xml (преодоление Java Util входа в SLF4J)
  3. На ваш главный до инициализации c3p0 добавить ниже фрагмент кода:

    // Getting JUL root logger 
    Logger logger = java.util.logging.LogManager.getLogManager().getLogger(""); 
    
    // Remove already attached Console handler which is responsible for above trouble 
    for (Handler handler : logger.getHandlers()) { 
        handler.close(); 
        logger.removeHandler(handler); 
    } 
    
    // Let SLF4J bridge configure its own handler(s) 
    SLF4JBridgeHandler.install();