2014-09-18 77 views
0

我已经设置了日志记录,我已经开发了一个项目的调用方法或行号,但我似乎无法得到行号和调用方法在日志中显示出来。我有一个Maven项目,以及maven-compiler-plugin被配置为包括在已编译的类调试信息。记录不会显示

这将会是非常有益的,让我有在日志信息,对我理解为什么这是不对的,现在发生的事情。有人能帮助向我解释什么是怎么回事,我如何能得到方法名和行号在我的日志?

这里是我的POM:

<?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> 

    <properties> 
     <cxf.version>3.0.1</cxf.version> 
     <log4j.version>2.0.2</log4j.version> 
     <wsdl.dir>generated\wsdl</wsdl.dir> 
    </properties> 

    <groupId>com.company</groupId> 
    <artifactId>webservices</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <name>Nuance-to-Edify Web Services</name> 
    <description>This project will handle communication between servers.</description> 

    <build> 
     <finalName>n2e-ws</finalName> 

     <plugins> 
      <!-- CREATE WAR --> 
      <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 

       <configuration> 
        <webResources> 
         <!-- INCLUDE SOURCE FILES WITH WAR --> 
         <resource> 
          <directory>${project.build.sourceDirectory}</directory> 
          <targetPath>WEB-INF/classes</targetPath> 
         </resource> 

         <!-- INCLUDE RESOURCES WITH WAR --> 
         <resource> 
          <directory>${project.build.sourceDirectory}\..\resources</directory> 
          <targetPath>WEB-INF/classes</targetPath> 
         </resource> 

         <!-- INCLUDE WSDLS WITH WAR --> 
         <resource> 
          <directory>${project.build.directory}\${wsdl.dir}</directory> 
          <targetPath>WEB-INF/wsdl</targetPath> 
         </resource> 
        </webResources> 
       </configuration> 
      </plugin> 

      <!-- GENERATE WSDL FOR EACH SERVICE --> 
      <plugin> 
       <groupId>org.apache.cxf</groupId> 
       <artifactId>cxf-java2ws-plugin</artifactId> 
       <version>${cxf.version}</version> 

       <dependencies> 
        <dependency> 
         <groupId>org.apache.cxf</groupId> 
         <artifactId>cxf-rt-frontend-jaxws</artifactId> 
         <version>${cxf.version}</version> 
        </dependency> 
       </dependencies> 

       <executions> 
        <execution> 
         <id>generate-account-service-wsdl</id> 
         <phase>prepare-package</phase> 
         <configuration> 
          <className>com.company.ws.data.services.interfaces.AccountServiceEndpointInterface</className> 
          <outputFile>${project.build.directory}\${wsdl.dir}\AccountService.wsdl</outputFile> 
          <address>REPLACE_WITH_ACTUAL_URL</address> 
          <genWsdl>true</genWsdl> 
          <verbose>true</verbose> 
         </configuration> 
         <goals> 
          <goal>java2ws</goal> 
         </goals> 
        </execution> 

        <execution> 
         <id>generate-logging-service-wsdl</id> 
         <phase>prepare-package</phase> 
         <configuration> 
          <className>com.company.ws.data.services.interfaces.LoggingServiceEndpointInterface</className> 
          <outputFile>${project.build.directory}\${wsdl.dir}\LoggingService.wsdl</outputFile> 
          <address>REPLACE_WITH_ACTUAL_URL</address> 
          <genWsdl>true</genWsdl> 
          <verbose>true</verbose> 
         </configuration> 
         <goals> 
          <goal>java2ws</goal> 
         </goals> 
        </execution> 

        <execution> 
         <id>generate-search-service-wsdl</id> 
         <phase>prepare-package</phase> 
         <configuration> 
          <className>com.company.ws.data.services.interfaces.SearchServiceEndpointInterface</className> 
          <outputFile>${project.build.directory}\${wsdl.dir}\SearchService.wsdl</outputFile> 
          <address>REPLACE_WITH_ACTUAL_URL</address> 
          <genWsdl>true</genWsdl> 
          <verbose>true</verbose> 
         </configuration> 
         <goals> 
          <goal>java2ws</goal> 
         </goals> 
        </execution> 

        <execution> 
         <id>generate-validation-service-wsdl</id> 
         <phase>prepare-package</phase> 
         <configuration> 
          <className>com.company.ws.data.services.interfaces.ValidationServiceEndpointInterface</className> 
          <outputFile>${project.build.directory}\${wsdl.dir}\ValidationService.wsdl</outputFile> 
          <address>REPLACE_WITH_ACTUAL_URL</address> 
          <genWsdl>true</genWsdl> 
          <verbose>true</verbose> 
         </configuration> 
         <goals> 
          <goal>java2ws</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 

     <pluginManagement> 
      <plugins> 
       <plugin> 
        <!-- mvn clean install tomcat:run-war to deploy Look for "Running war 
         on http://xxx" and "Setting the server's publish address to be /yyy" in console 
         output; WSDL browser address will be concatenation of the two: http://xxx/yyy?wsdl --> 
        <groupId>org.apache.tomcat.maven</groupId> 
        <artifactId>tomcat7-maven-plugin</artifactId> 
        <version>2.0</version> 
        <executions> 
         <execution> 
          <id>start-tomcat</id> 
          <goals> 
           <goal>run-war</goal> 
          </goals> 
          <phase>pre-integration-test</phase> 
          <configuration> 
           <port>${test.server.port}</port> 
           <path>/*</path> 
           <fork>true</fork> 
           <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>3.1</version> 
        <configuration> 
         <source>1.7</source> 
         <target>1.7</target> 
         <debug>true</debug> 
         <debuglevel>lines,source,vars</debuglevel> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-eclipse-plugin</artifactId> 
        <version>2.9</version> 
        <configuration> 
         <projectNameTemplate>[artifactId]-[version]</projectNameTemplate> 
         <wtpmanifest>true</wtpmanifest> 
         <wtpapplicationxml>true</wtpapplicationxml> 
         <wtpversion>3.5</wtpversion> 
        </configuration> 
       </plugin> 
       <!--This plugin's configuration is used to store Eclipse m2e settings 
        only. It has no influence on the Maven build itself. --> 
       <plugin> 
        <groupId>org.eclipse.m2e</groupId> 
        <artifactId>lifecycle-mapping</artifactId> 
        <version>1.0.0</version> 
        <configuration> 
         <lifecycleMappingMetadata> 
          <pluginExecutions> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId> 
              org.apache.cxf 
             </groupId> 
             <artifactId> 
              cxf-java2ws-plugin 
             </artifactId> 
             <versionRange> 
              [${cxf.version},) 
             </versionRange> 
             <goals> 
              <goal>java2ws</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <ignore></ignore> 
            </action> 
           </pluginExecution> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId> 
              org.apache.maven.plugins 
             </groupId> 
             <artifactId> 
              maven-compiler-plugin 
             </artifactId> 
             <versionRange> 
              [2.3.2,) 
             </versionRange> 
             <goals> 
              <goal>testCompile</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <ignore></ignore> 
            </action> 
           </pluginExecution> 
          </pluginExecutions> 
         </lifecycleMappingMetadata> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

    <dependencies> 
     <!-- COMPILE DEPENDENCIES --> 
     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-rt-frontend-jaxws</artifactId> 
      <version>${cxf.version}</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-rt-transports-http</artifactId> 
      <version>${cxf.version}</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-api</artifactId> 
      <version>${log4j.version}</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-core</artifactId> 
      <version>${log4j.version}</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-lang3</artifactId> 
      <version>3.3.2</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-digester3</artifactId> 
      <version>3.2</version> 
      <scope>compile</scope> 
      <classifier>with-deps</classifier> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>4.1.0.RELEASE</version> 
      <scope>compile</scope> 
     </dependency> 

     <!-- PROVIDED/TEST DEPENDENCIES --> 
     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-web-api</artifactId> 
      <version>6.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jmock</groupId> 
      <artifactId>jmock-junit4</artifactId> 
      <version>2.6.0</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jmock</groupId> 
      <artifactId>jmock-legacy</artifactId> 
      <version>2.6.0</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

这是我的log4j2.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?> 
<Configuration 
    status="debug" 
    monitorInterval="600"> 

    <Appenders> 
     <Console 
      name="CONSOLE" 
      target="SYSTEM_OUT"> 
      <PatternLayout 
       pattern="%d [%4.4t] [%5.5p] %35.35c(%15.15M):%-5.5L - %m%n" /> 
     </Console> 
     <File 
      name="EDIFY-NUANCE" 
      fileName="../logs/n2e-ws.log"> 
      <!--<PatternLayout 
       pattern="%d [%4.4t] [%5.5p] %35.35c(%15.15M):%-5.5L - %m%n" />--> 
      <PatternLayout pattern="%d %5p %20.30c [%t] %20.30C (%F:%L) %m%n" 
       /> 
     </File> 
     <Async name="ASYNC"> 
      <AppenderRef ref="EDIFY-NUANCE" /> 
      <AppenderRef ref="CONSOLE" /> 
     </Async> 
    </Appenders> 

    <Loggers> 
     <logger 
      name="log4j.logger.httpclient.wire.header" 
      level="fatal" 
      additivity="false" /> 
     <Root level="debug"> 
      <AppenderRef ref="ASYNC" /> 
     </Root> 
    </Loggers> 
</Configuration> 

回答

1

你需要指定在配置includeLocation="true"用于异步记录仪或异步追加程序。另请参阅http://logging.apache.org/log4j/2.x/manual/async.html#Locationhttp://logging.apache.org/log4j/2.x/manual/appenders.html#AsyncAppender

顺便说一句,您的配置有一个没有AppenderRef的记录器(名称为“log4j.logger.httpclient.wire.header”)。这是行不通的。

因此,把那些一起和你的配置应该是这样的:

<Appenders> 
    ... 
    <Async name="ASYNC" includeLocation="true"> 
     <AppenderRef ref="EDIFY-NUANCE" /> 
     <AppenderRef ref="CONSOLE" /> 
    </Async> 
</Appenders> 
<Loggers> 
    <Logger name="log4j.logger.httpclient.wire.header" 
      level="fatal" additivity="false"> 
     <AppenderRef ref="ASYNC" /> 
    </Logger> 
    <Root level="debug"> 
     <AppenderRef ref="ASYNC" /> 
    </Root> 
</Loggers> 
+1

你让我在正确的轨道上,但我确实有修改意见,以让我的问题解决了。我想特别感谢您提供与该主题相关的参考资料和文章。这就是说,'属性includeLocation =“真”'必须添加到异步的appender:'<异步名=“异步” includeLocation =“真”> ...'如果你修改你的答案,以反映这一点,我会将其标记为已接受。 – liltitus27 2014-09-19 14:04:06

+1

你说得对,感谢您的指正! – 2014-09-19 17:42:13