我使用java 1.6,Eclipse Juno,weblogic 10.3.6,Maven。
我想在我的项目中配置log4j。我在pom.xml中添加了log4j依赖项。我配置了log4j.xml
但是当我使用weblogic服务器从eclipse部署我的项目时,log4j并没有启动。在控制台中,我没有看到log4j消息。
我认为这是一个地方log4j.xml问题
如何在服务器weblogic中配置log4j?
我的项目具有以下结构
我的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>eusurveyadmin</groupId>
<artifactId>eusurveyadmin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.3.Final</version>
<type>jar</type>
<!-- <scope>compile</scope> -->
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
log4j.xml是
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
Appenders
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<appender name="info" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/temp/logs/esurveyadmin-info.log" />
<param name="MaxFileSize" value="4096KB" />
<param name="MaxBackupIndex" value="20" />
<param name="Append" value="true" />
<param name="Threshold" value="Info" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}-%-4r [%t] (%F:%L) %-5p %c %x - %m%n" />
</layout>
</appender>
<appender name="error" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/temp/logs/esurveyadmin-error.log" />
<param name="MaxFileSize" value="5120KB" />
<param name="MaxBackupIndex" value="20" />
<param name="Append" value="true" />
<param name="Threshold" value="Error" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}-%-4r [%t] (%F:%L) %-5p %c %x - %m%n" />
</layout>
</appender>
<category name="org.hibernate.engine.jdbc.spi.SqlExceptionHelper">
<priority value="off"/>
</category>
<logger name="com.eusurveyadmin.controller">
<level value="info" />
<appender-ref ref="error" />
<appender-ref ref="info" />
</logger>
<logger name="eusurveyadmin.daos.implementacion">
<level value="info" />
<appender-ref ref="console" />
<appender-ref ref="error" />
<appender-ref ref="info" />
</logger>
<!-- 3rdparty Loggers -->
<logger name="org.springframework.core">
<level value="warn" />
<appender-ref ref="error" />
<appender-ref ref="info" />
</logger>
<logger name="org.springframework.beans">
<level value="warn" />
<appender-ref ref="error" />
<appender-ref ref="info" />
</logger>
<logger name="org.springframework.context">
<level value="warn" />
<appender-ref ref="error" />
<appender-ref ref="info" />
</logger>
<logger name="org.springframework.web">
<level value="warn" />
<appender-ref ref="error" />
<appender-ref ref="info" />
</logger>
<logger name="org.hibernate">
<level value="warn" />
<appender-ref ref="error" />
<appender-ref ref="info" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
<appender-ref ref="info" />
<appender-ref ref="error" />
</root>
</log4j:configuration>
我是否必须再进行配置?
我读了其他帖子,我有pom.xml依赖项,log4j.xml。
答案 0 :(得分:0)
要使您的log4j配置正常工作,它应该位于/WEB-INF/classes
目录下的类路径中。
要使Maven在此路径下的最终log4j.xml
文件中包含您的war
,maven希望将其放在其中一个资源目录中。
正如@jens所提到的,要在您的网络应用程序中加入log4j.xml
,请将其放在项目的/src/main/resources/
目录中,或者使用Maven&#39; {定义您自己的资源目录{1}}标记。