如何使用 log4j2 记录整个应用程序?
How to use log4j2 to logging entire application?
我不确定我的应用程序是否与 log4j2 正确集成,但我的 objective 非常清楚。我想在我的日志文件中捕获每一个微小的 logging information
。 logging information
包括 spring framework loading + apache tiles loading + my app loading and runtime logging.
虽然我能够捕获 org.springframework
日志记录详细信息但无法为 org.apache.tiles.
这样做,但是,我确实在我的控制台中捕获了所有日志记录信息。
并不是说没有从磁贴日志记录中捕获任何东西,我确实捕获了,但是它的日志记录信息很少。我在控制台中看到的日志信息量与日志文件中的日志信息量相去甚远。
这是我的 log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Configuration monitorInterval="60">
<Properties>
<Property name="filename">D://log/</Property>
</Properties>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
<File name="LOGFILE" fileName="${filename}/SpringWebJsp.log">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</File>
</Appenders>
<Loggers>
<Logger name="com.jio.tiny" level="info" additivity="true">
<AppenderRef ref="LOGFILE" level="info" />
</Logger>
<Logger name="org.springframework" level="info" additivity="true">
<appender-ref ref="LOGFILE" level="info" />
</Logger>
<Logger name="org.apache.tiles" level="debug" additivity="true">
<appender-ref ref="LOGFILE" level="debug" />
</Logger>
<!--<Logger name="org.springframework.security" level="debug" additivity="true">
<appender-ref ref="LOGFILE" level="debug" />
</Logger> -->
<!-- <Logger name="org.thymeleaf" level="info" additivity="true">
<appender-ref ref="LOGFILE" level="info" />
</Logger> -->
<!-- <Logger name="org.hibernate" level="info" additivity="true">
<appender-ref ref="LOGFILE" level="info" />
</Logger> -->
<Root level="debug">
<AppenderRef ref="STDOUT" />
</Root>
</Loggers>
</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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jio.tiny</groupId>
<artifactId>SpringWebJsp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SpringWebJsp Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<apachetiles.version>3.0.5</apachetiles.version>
<apache.logger.version>2.8.2</apache.logger.version>
</properties>
<repositories>
<repository>
<id>io.spring.repo.maven.release</id>
<url>http://repo.spring.io/release/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.1.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- Apache Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>${apachetiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>${apachetiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>${apachetiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${apachetiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Apache Log4j2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${apache.logger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${apache.logger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${apache.logger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${apache.logger.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.6</version>
</dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>1.7.24</version>
</dependency>
<!-- Servlet+JSP+JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>3.2</version> -->
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>SpringWebJsp</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>
D://log/jars/
</outputDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>SpringWebJsp</finalName>
</build>
</project>
记录在控制台中捕获的图块
[DEBUG] 2017-07-04 22:02:57.504 [tomcat-http--2] sax - setDocumentLocator(com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser$LocatorProxy@261c3a65)
[DEBUG] 2017-07-04 22:02:57.504 [tomcat-http--2] sax - startDocument()
[DEBUG] 2017-07-04 22:02:57.504 [tomcat-http--2] sax - resolveEntity('-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN', 'http://tiles.apache.org/dtds/tiles-config_3_0.dtd')
[DEBUG] 2017-07-04 22:02:57.504 [tomcat-http--2] Digester - Resolving to alternate DTD 'jar:file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/lib/tiles-core-3.0.5.jar!/org/apache/tiles/resources/tiles-config_3_0.dtd'
[DEBUG] 2017-07-04 22:02:57.506 [tomcat-http--2] sax - startElement(,tiles-definitions,tiles-definitions)
[DEBUG] 2017-07-04 22:02:57.506 [tomcat-http--2] Digester - Pushing body text ''
[DEBUG] 2017-07-04 22:02:57.506 [tomcat-http--2] Digester - New match='tiles-definitions'
[DEBUG] 2017-07-04 22:02:57.506 [tomcat-http--2] Digester - No rules found matching 'tiles-definitions'.
[DEBUG] 2017-07-04 22:02:57.507 [tomcat-http--2] sax - ignorableWhitespace(
)
[DEBUG] 2017-07-04 22:02:57.507 [tomcat-http--2] sax - ignorableWhitespace(
)
.
.
Similar piles of log continue
.
.
[DEBUG] 2017-07-04 22:02:57.540 [tomcat-http--2] BaseLocaleUrlDefinitionDAO - File Resource file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/views/tiles/tiles_en.xml at file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/views/tiles/tiles_en.xml not found, continue
[DEBUG] 2017-07-04 22:02:57.540 [tomcat-http--2] BaseLocaleUrlDefinitionDAO - File Resource file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/views/tiles/tiles_en_US.xml at file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/views/tiles/tiles_en_US.xml not found, continue
[DEBUG] 2017-07-04 22:02:57.654 [tomcat-http--2] ResolvingLocaleUrlDefinitionDAO - Resolve definition for child name='home' extends='base-definition.
[DEBUG] 2017-07-04 22:02:57.654 [tomcat-http--2] ResolvingLocaleUrlDefinitionDAO - Resolve definition for child name='products' extends='base-definition.
[DEBUG] 2017-07-04 22:02:57.654 [tomcat-http--2] ResolvingLocaleUrlDefinitionDAO - Resolve definition for child name='contactus' extends='base-definition.
[DEBUG] 2017-07-04 22:02:57.661 [tomcat-http--2] BasicTilesContainer - Render request received for definition 'home'
我的日志文件能够捕获的日志量只是上述日志详细信息的最后六行。
不知行为是否正常!
The amount of logging information in the console is not even little
close in the log file. Is this behavior ok?
是。
根据您的配置文件,您只在日志文件中写入了 3 个包(com.jio.tiny
、org.springframework
和 org.apache.tiles
)的日志。但是每个日志(级别 debug
或更高)都在控制台中写入,包括上述 3 个包的日志。所以预计控制台的日志可能比文件多。
Is it possible to set the console and log file to have same logs? How?
从 Loggers
部分删除额外的 Logger
定义,并引用文件附加程序和控制台附加程序。因此,要在控制台和日志文件中有相同的日志,您的 Loggers
部分可以如下所示:
<Loggers>
<Root level="debug">
<AppenderRef ref="STDOUT" />
<AppenderRef ref="LOGFILE" />
</Root>
</Loggers>
我不确定我的应用程序是否与 log4j2 正确集成,但我的 objective 非常清楚。我想在我的日志文件中捕获每一个微小的 logging information
。 logging information
包括 spring framework loading + apache tiles loading + my app loading and runtime logging.
虽然我能够捕获 org.springframework
日志记录详细信息但无法为 org.apache.tiles.
这样做,但是,我确实在我的控制台中捕获了所有日志记录信息。
并不是说没有从磁贴日志记录中捕获任何东西,我确实捕获了,但是它的日志记录信息很少。我在控制台中看到的日志信息量与日志文件中的日志信息量相去甚远。
这是我的 log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Configuration monitorInterval="60">
<Properties>
<Property name="filename">D://log/</Property>
</Properties>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
<File name="LOGFILE" fileName="${filename}/SpringWebJsp.log">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</File>
</Appenders>
<Loggers>
<Logger name="com.jio.tiny" level="info" additivity="true">
<AppenderRef ref="LOGFILE" level="info" />
</Logger>
<Logger name="org.springframework" level="info" additivity="true">
<appender-ref ref="LOGFILE" level="info" />
</Logger>
<Logger name="org.apache.tiles" level="debug" additivity="true">
<appender-ref ref="LOGFILE" level="debug" />
</Logger>
<!--<Logger name="org.springframework.security" level="debug" additivity="true">
<appender-ref ref="LOGFILE" level="debug" />
</Logger> -->
<!-- <Logger name="org.thymeleaf" level="info" additivity="true">
<appender-ref ref="LOGFILE" level="info" />
</Logger> -->
<!-- <Logger name="org.hibernate" level="info" additivity="true">
<appender-ref ref="LOGFILE" level="info" />
</Logger> -->
<Root level="debug">
<AppenderRef ref="STDOUT" />
</Root>
</Loggers>
</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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jio.tiny</groupId>
<artifactId>SpringWebJsp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SpringWebJsp Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<apachetiles.version>3.0.5</apachetiles.version>
<apache.logger.version>2.8.2</apache.logger.version>
</properties>
<repositories>
<repository>
<id>io.spring.repo.maven.release</id>
<url>http://repo.spring.io/release/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.1.9.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- Apache Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>${apachetiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>${apachetiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>${apachetiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>${apachetiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Apache Log4j2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${apache.logger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${apache.logger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${apache.logger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${apache.logger.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.6</version>
</dependency> -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-ext</artifactId>
<version>1.7.24</version>
</dependency>
<!-- Servlet+JSP+JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>3.2</version> -->
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>SpringWebJsp</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>
D://log/jars/
</outputDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>SpringWebJsp</finalName>
</build>
</project>
记录在控制台中捕获的图块
[DEBUG] 2017-07-04 22:02:57.504 [tomcat-http--2] sax - setDocumentLocator(com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser$LocatorProxy@261c3a65)
[DEBUG] 2017-07-04 22:02:57.504 [tomcat-http--2] sax - startDocument()
[DEBUG] 2017-07-04 22:02:57.504 [tomcat-http--2] sax - resolveEntity('-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN', 'http://tiles.apache.org/dtds/tiles-config_3_0.dtd')
[DEBUG] 2017-07-04 22:02:57.504 [tomcat-http--2] Digester - Resolving to alternate DTD 'jar:file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/lib/tiles-core-3.0.5.jar!/org/apache/tiles/resources/tiles-config_3_0.dtd'
[DEBUG] 2017-07-04 22:02:57.506 [tomcat-http--2] sax - startElement(,tiles-definitions,tiles-definitions)
[DEBUG] 2017-07-04 22:02:57.506 [tomcat-http--2] Digester - Pushing body text ''
[DEBUG] 2017-07-04 22:02:57.506 [tomcat-http--2] Digester - New match='tiles-definitions'
[DEBUG] 2017-07-04 22:02:57.506 [tomcat-http--2] Digester - No rules found matching 'tiles-definitions'.
[DEBUG] 2017-07-04 22:02:57.507 [tomcat-http--2] sax - ignorableWhitespace(
)
[DEBUG] 2017-07-04 22:02:57.507 [tomcat-http--2] sax - ignorableWhitespace(
)
.
.
Similar piles of log continue
.
.
[DEBUG] 2017-07-04 22:02:57.540 [tomcat-http--2] BaseLocaleUrlDefinitionDAO - File Resource file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/views/tiles/tiles_en.xml at file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/views/tiles/tiles_en.xml not found, continue
[DEBUG] 2017-07-04 22:02:57.540 [tomcat-http--2] BaseLocaleUrlDefinitionDAO - File Resource file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/views/tiles/tiles_en_US.xml at file:/D:/sts-bundle/pivotal-tc-server-developer-3.2.4.SR1/base-instance/wtpwebapps/SpringWebJsp/WEB-INF/views/tiles/tiles_en_US.xml not found, continue
[DEBUG] 2017-07-04 22:02:57.654 [tomcat-http--2] ResolvingLocaleUrlDefinitionDAO - Resolve definition for child name='home' extends='base-definition.
[DEBUG] 2017-07-04 22:02:57.654 [tomcat-http--2] ResolvingLocaleUrlDefinitionDAO - Resolve definition for child name='products' extends='base-definition.
[DEBUG] 2017-07-04 22:02:57.654 [tomcat-http--2] ResolvingLocaleUrlDefinitionDAO - Resolve definition for child name='contactus' extends='base-definition.
[DEBUG] 2017-07-04 22:02:57.661 [tomcat-http--2] BasicTilesContainer - Render request received for definition 'home'
我的日志文件能够捕获的日志量只是上述日志详细信息的最后六行。
不知行为是否正常!
The amount of logging information in the console is not even little close in the log file. Is this behavior ok?
是。
根据您的配置文件,您只在日志文件中写入了 3 个包(com.jio.tiny
、org.springframework
和 org.apache.tiles
)的日志。但是每个日志(级别 debug
或更高)都在控制台中写入,包括上述 3 个包的日志。所以预计控制台的日志可能比文件多。
Is it possible to set the console and log file to have same logs? How?
从 Loggers
部分删除额外的 Logger
定义,并引用文件附加程序和控制台附加程序。因此,要在控制台和日志文件中有相同的日志,您的 Loggers
部分可以如下所示:
<Loggers>
<Root level="debug">
<AppenderRef ref="STDOUT" />
<AppenderRef ref="LOGFILE" />
</Root>
</Loggers>