- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要支持将特定包记录到 chats.log 中,并将错误记录到 error.log 中。如何正确执行此操作?到目前为止,我在几个附加程序中创建了阈值过滤器,但 error.log 保持为空,并且 chats.log 有一个条目,该条目不属于特定包。毕竟,我仔细阅读了 log4j 的文档,并尝试了 2 天解决这个问题,并遵循了网站和 youtube 上的几个教程。我也尝试过这个:Apache Log4j2 package specific logging using log4j2.xml我也尝试了旧的 log4j 教程,但这以错误结束。
这些是我在 Maven 项目结构中使用的文件。src/main/resources/log4j2.properties
status = error
name = PropertiesConfig
######################################
# Global properties as varies
######################################
property.logPath = logs
######################################
# Filters and properties of filters
######################################
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = all
######################################
# Appenders Section for roles
######################################
appenders = rolling, console, rolling2, errorAppender, service
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.immediateFlush= true
appender.rolling.append = true
appender.rolling.fileName = ${logPath}/server.log
appender.rolling.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20
appender.rolling.filter.threshold.type = LevelRangeFilter
appender.rolling.filter.threshold.minLevel = INFO
appender.rolling.filter.threshold.maxLevel = INFO
appender.rolling.filter.threshold.onMatch = ACCEPT
appender.rolling.filter.threshold.onMismatch = DENY
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling2.type = RollingFile
appender.rolling2.name = debugLog
appender.rolling2.immediateFlush= true
appender.rolling2.append = true
appender.rolling2.fileName = ${logPath}/debug.log
appender.rolling2.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling2.layout.type = PatternLayout
appender.rolling2.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling2.policies.type = Policies
appender.rolling2.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling2.policies.time.interval = 1
appender.rolling2.policies.time.modulate = true
appender.rolling2.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling2.policies.size.size=10MB
appender.rolling2.strategy.type = DefaultRolloverStrategy
appender.rolling2.strategy.max = 20
appender.rolling2.filter.threshold.type = LevelRangeFilter
appender.rolling2.filter.threshold.minLevel = DEBUG
appender.rolling2.filter.threshold.maxLevel = DEBUG
appender.rolling2.filter.threshold.onMatch = ACCEPT
appender.rolling2.filter.threshold.onMismatch = DENY
appender.errorAppender.type = RollingFile
appender.errorAppender.name = errorLog
appender.errorAppender.immediateFlush= true
appender.errorAppender.append = true
appender.errorAppender.fileName = ${logPath}/error.log
appender.errorAppender.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.errorAppender.layout.type = PatternLayout
appender.errorAppender.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.errorAppender.policies.type = Policies
appender.errorAppender.policies.time.type = TimeBasedTriggeringPolicy
appender.errorAppender.policies.time.interval = 1
appender.errorAppender.policies.time.modulate = true
appender.errorAppender.policies.size.type = SizeBasedTriggeringPolicy
appender.errorAppender.policies.size.size=10MB
appender.errorAppender.strategy.type = DefaultRolloverStrategy
appender.errorAppender.strategy.max = 20
appender.errorAppender.filter.threshold.type = LevelRangeFilter
appender.errorAppender.filter.threshold.minLevel = ERROR
appender.errorAppender.filter.threshold.maxLevel = ERROR
appender.errorAppender.filter.threshold.onMatch = ACCEPT
appender.errorAppender.filter.threshold.onMismatch = DENY
appender.service.type = RollingFile
appender.service.name = chats
appender.service.append = true
appender.service.fileName = ${logPath}/chats.log
appender.service.filePattern = chats-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.service.layout.type = PatternLayout
appender.service.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.service.policies.type = Policies
appender.service.policies.time.type = TimeBasedTriggeringPolicy
appender.service.policies.time.interval = 1
appender.service.policies.time.modulate = true
appender.service.policies.size.type = SizeBasedTriggeringPolicy
appender.service.policies.size.size=10MB
appender.service.strategy.type = DefaultRolloverStrategy
appender.service.strategy.max = 20
appender.service.filter.threshold.type = LevelRangeFilter
appender.service.filter.threshold.minLevel = INFO
appender.service.filter.threshold.maxLevel = INFO
appender.service.filter.threshold.onMatch = ACCEPT
appender.service.filter.threshold.onMismatch = DENY
######################################
# Loggers Section for file write
######################################
loggers = rolling, package
logger.rolling.name = org.remad.logging
logger.rolling.appenderRefs = rolling, debugLog, errorLog
logger.rolling.level = all
logger.rolling.additivity = true
logger.rolling.appenderRef.rolling.ref = RollingFile
logger.rolling.appenderRef.rolling2.ref = debugLog
logger.package.name = org.remad.logging.protocol.Protocol
logger.package.appenderRefs = service
logger.package.level = info
logger.package.additivity = false
logger.package.appenderRef.service.ref = chats
######################################
# RootLogger Section for settings
######################################
rootLogger.level = all
rootLogger.appenderRefs = stdout, chats, errorLog
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.service.ref = chats
rootLogger.apenderRef.errorAppender.ref = errorLog
pom.xml
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.remad</groupId>
<artifactId>Logging</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- ====================================================================== -->
<!-- Global project properties -->
<!-- ====================================================================== -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- ====================================================================== -->
<!-- project Dependencies -->
<!-- ====================================================================== -->
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.2</version>
</dependency>
</dependencies>
<!-- ====================================================================== -->
<!-- project build with plugins -->
<!-- ====================================================================== -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.remad.logging.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
src/main/org.remad.logging.Main.java
package org.remad.logging;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.remad.logging.protocol.Protocol;
public class Main {
private static final Logger logger = LogManager.getLogger(Main.class);
public static void main(String[] args) {
String message = "Hello there!";
LoggerEntryPoint loggerEntryPoint = new LoggerEntryPoint();
Protocol protocol = new Protocol();
logger.trace(message);
logger.debug(message);
logger.info(message);
logger.warn(message);
logger.error(message);
logger.fatal(message);
loggerEntryPoint.entries();
protocol.logSomeMessages();
}
}
org.remad.logging.LoggerEntryPoint.java
package org.remad.logging;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LoggerEntryPoint {
private static final Logger logger = LogManager.getLogger(LoggerEntryPoint.class);
public LoggerEntryPoint() {}
public void entries() {
logger.info("now in " + getClass().getCanonicalName());
logger.error("now error.");
logger.debug("hggxdfghcdft");
}
}
org.remad.logging.protocol.Protocol.java
package org.remad.logging.protocol;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Protocol {
public Protocol() {}
private static final Logger logger = LogManager.getLogger(Protocol.class);
public void logSomeMessages() {
logger.fatal("Fatal error.");
logger.error("Error happened.");
logger.warn("Warning message.");
logger.info("This message informs.");
logger.debug("Debug message.");
logger.info("This is also chat message");
}
}
日志/server.log
2020-05-18 17:24:42 INFO Main:17 - Hello there!
2020-05-18 17:24:42 INFO LoggerEntryPoint:13 - now in org.remad.logging.LoggerEntryPoint
日志/错误.log
日志/debug.log
2020-05-18 17:24:42 DEBUG Main:16 - Hello there!
2020-05-18 17:24:42 DEBUG LoggerEntryPoint:15 - hggxdfghcdft
日志/chats.log
2020-05-18 17:24:42 INFO Main:17 - Hello there!
2020-05-18 17:24:42 INFO LoggerEntryPoint:13 - now in org.remad.logging.LoggerEntryPoint
2020-05-18 17:24:42 INFO Protocol:16 - This message informs.
2020-05-18 17:24:42 INFO Protocol:18 - This is also chat message
最佳答案
您有一个级别设置为“全部”的全局阈值过滤器。这意味着每个日志事件都将被发送到附加程序,无论记录器上设置的日志记录级别如何。您还将根日志记录级别设置为“全部”。这是一种非常糟糕的做法,因为它将导致性能问题,因为每个日志记录调用都会创建一个 LogEvent,并且因为您正在捕获行号,所以每个事件都需要通过遍历线程的堆栈跟踪来捕获位置信息。
摆脱全局阈值过滤器。您的情况不需要它。将根日志记录级别设置为 DEBUG,然后设置附加程序引用的日志记录级别以匹配您想要记录的内容。
我已将您的配置修改为我认为可行的配置,但我还没有尝试过。我更喜欢 XML 语法,所以如果我打错了,请不要感到惊讶。
status = error
name = PropertiesConfig
######################################
# Global properties as varies
######################################
property.logPath = logs
######################################
# Appenders Section for roles
######################################
appenders = rolling, console, rolling2, errorAppender, service
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.immediateFlush= true
appender.rolling.append = true
appender.rolling.fileName = ${logPath}/server.log
appender.rolling.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20
appender.rolling.filter.threshold.type = LevelRangeFilter
appender.rolling.filter.threshold.minLevel = INFO
appender.rolling.filter.threshold.maxLevel = INFO
appender.rolling.filter.threshold.onMatch = ACCEPT
appender.rolling.filter.threshold.onMismatch = DENY
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling2.type = RollingFile
appender.rolling2.name = debugLog
appender.rolling2.immediateFlush= true
appender.rolling2.append = true
appender.rolling2.fileName = ${logPath}/debug.log
appender.rolling2.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling2.layout.type = PatternLayout
appender.rolling2.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling2.policies.type = Policies
appender.rolling2.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling2.policies.time.interval = 1
appender.rolling2.policies.time.modulate = true
appender.rolling2.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling2.policies.size.size=10MB
appender.rolling2.strategy.type = DefaultRolloverStrategy
appender.rolling2.strategy.max = 20
appender.rolling2.filter.threshold.type = LevelRangeFilter
appender.rolling2.filter.threshold.minLevel = DEBUG
appender.rolling2.filter.threshold.maxLevel = DEBUG
appender.rolling2.filter.threshold.onMatch = ACCEPT
appender.rolling2.filter.threshold.onMismatch = DENY
appender.errorAppender.type = RollingFile
appender.errorAppender.name = errorLog
appender.errorAppender.immediateFlush= true
appender.errorAppender.append = true
appender.errorAppender.fileName = ${logPath}/error.log
appender.errorAppender.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.errorAppender.layout.type = PatternLayout
appender.errorAppender.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.errorAppender.policies.type = Policies
appender.errorAppender.policies.time.type = TimeBasedTriggeringPolicy
appender.errorAppender.policies.time.interval = 1
appender.errorAppender.policies.time.modulate = true
appender.errorAppender.policies.size.type = SizeBasedTriggeringPolicy
appender.errorAppender.policies.size.size=10MB
appender.errorAppender.strategy.type = DefaultRolloverStrategy
appender.errorAppender.strategy.max = 20
appender.errorAppender.filter.threshold.type = LevelRangeFilter
appender.errorAppender.filter.threshold.minLevel = ERROR
appender.errorAppender.filter.threshold.maxLevel = ERROR
appender.errorAppender.filter.threshold.onMatch = ACCEPT
appender.errorAppender.filter.threshold.onMismatch = DENY
appender.service.type = RollingFile
appender.service.name = chats
appender.service.append = true
appender.service.fileName = ${logPath}/chats.log
appender.service.filePattern = chats-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.service.layout.type = PatternLayout
appender.service.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.service.policies.type = Policies
appender.service.policies.time.type = TimeBasedTriggeringPolicy
appender.service.policies.time.interval = 1
appender.service.policies.time.modulate = true
appender.service.policies.size.type = SizeBasedTriggeringPolicy
appender.service.policies.size.size=10MB
appender.service.strategy.type = DefaultRolloverStrategy
appender.service.strategy.max = 20
appender.service.filter.threshold.type = LevelRangeFilter
appender.service.filter.threshold.minLevel = INFO
appender.service.filter.threshold.maxLevel = INFO
appender.service.filter.threshold.onMatch = ACCEPT
appender.service.filter.threshold.onMismatch = DENY
######################################
# Loggers Section for file write
######################################
loggers = rolling, package
logger.rolling.name = org.remad.logging
logger.rolling.appenderRefs = rolling, rolling2
logger.rolling.level = DEBUG
logger.rolling.additivity = true
logger.rolling.appenderRef.rolling.ref = RollingFile
logger.rolling.appenderRef.rolling.level = INFO
logger.rolling.appenderRef.rolling2.ref = debugLog
logger.rolling.appenderRef.rolling2.ref = DEBUG
logger.package.name = org.remad.logging.protocol.Protocol
logger.package.appenderRefs = service
logger.package.level = info
logger.package.additivity = false
logger.package.appenderRef.service.ref = chats
logger.package.appenderRef.service.level = INFO
######################################
# RootLogger Section for settings
######################################
rootLogger.level = INFO
rootLogger.appenderRefs = stdout, chats, errorLog
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.stdout.level = INFO
rootLogger.appenderRef.service.ref = chats
rootLogger.appenderRef.service.level = INFO
rootLogger.apenderRef.errorAppender.ref = errorLog
rootLogger.appenderRef.errorAppender.ref = ERROR
我将过滤器留在了 Appender 上,以仅过滤您想要的级别。我不确定为什么你只想要特定 Appender 上的 INFO 或 ERROR 消息,而不是该级别的默认消息和更具体的消息,但我保留了它。如果您确实不需要,请删除这些过滤器。
关于java - log4j2如何记录包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61874348/
在C语言中,当有变量(假设都是int)i小于j时,我们可以用等式 i^=j^=i^=j 交换两个变量的值。例如,令int i = 3,j = 5;在计算 i^=j^=i^=j 之后,我有 i = 5,
我为以下问题编写了以下代码: 给定一个由 N 个正整数组成的序列 A,编写一个程序来查找满足 i > A[j]A[i](A[i] 的 A[j] 次方 > A[j] 的 A[i] 次方)。 我的代码通过
这个表达式是从左到右解析的吗?我试图解释解析的结果,但最后的结果是错误的。 int j=10, k=10; j+=j-=j*=j; //j=j+(j-=j*=j)=j+(j-j*j) k+=k*=
给定一个整数数组 A ,我试图找出在给定位置 j ,A[j] 从每个 i=0 到 i=j 在 A 中出现了多少次。我设计了一个如下所示的解决方案 map CF[400005]; for(int i=0
你能帮我算法吗: 给定 2 个相同大小的数组 a[]和 b[]具有大于或等于 1 的整数。 查找不相等的索引 i和 j ( i != j ) 使得值 -max(a[i]*b[i] + a[i] * b
每次用J的M.副词,性能显着下降。因为我怀疑艾弗森和许比我聪明得多,我一定是做错了什么。 考虑 Collatz conjecture .这里似乎有各种各样的内存机会,但不管我放在哪里M. ,性能太差了
假设一个包含各种类型的盒装矩阵: matrix =: ('abc';'defgh';23),:('foo';'bar';45) matrix +---+-----+--+|abc|defgh|23|+
是否有可能对于两个正整数 i 和 j,(-i)/j 不等于 -(i/j)?我不知道这是否可能......我认为这将是关于位的东西,或者 char 类型的溢出或其他东西,但我找不到它。有什么想法吗? 最
假设两个不同大小的数组: N0 =: i. 50 N1 =: i. 500 应该有一种方法可以获得唯一的对,只需将两者结合起来即可。我发现的“最简单”是: ]$R =: |:,"2 |: (,.N0)
我是 J 的新用户,我只是想知道 J 包中是否实现了三次样条插值方法? 最佳答案 我自己不熟悉,但是我确实安装了所有的包,所以 $ rg -l -i spline /usr/share/j/9.02
在 Q/kdb 中,您可以使用 ': 轻松修改动词,它代表每个优先级。它会将动词应用于一个元素及其之前的邻居。例如 =': 检查值对是否相等。在 J 中,您可以轻松折叠 /\ 但它是累积的,是否有成对
嗨,我有一个 4x4 双矩阵 A 1+2i 2-1i -3-2i -1+4i 3-1i -3+2i 1-3i -1-3i 4+3i 3+5i 1-2i -1-4i
刚刚发现 J 语言,我输入: 1+^o.*0j1 I expected the answer to be 0 ,但我得到了 0j1.22465e_16。虽然这非常接近于 0,但我想知道为什么 J 应该
这个问题在这里已经有了答案: With arrays, why is it the case that a[5] == 5[a]? (20 个答案) 关闭 3 年前。 我正在阅读“C++ 编程语言”
当第一行是 1, 1/2 , 1/3 ....这是支持该问题的图像。 是否存在比朴素的 O(n^2) 方法更有效的方法? 我在研究伯努利数时遇到了这个问题,然后在研究“Akiyama-Tanigawa
我写了一段Java代码,它在无限循环中运行。 下面是代码: public class TestProgram { public static void main(String[] args){
for (int i = n; i > 0; i /= 2) { for (int j = 0; j 0; i /= 2) 的第一个循环结果 O(log N) . 第二个循环for (int
如问题中所述,需要找到数组中 (i,j) 对的总数,使得 (1) **ia[j]** 其中 i 和 j 是数组的索引。没有空间限制。 我的问题是 1) Is there any approach w
for l in range(1,len(S)-1): for i in range(1,len(S)-l): j=i+l for X in N:
第二个for循环的复杂度是多少?会是n-i吗?根据我的理解,第一个 for 循环将执行 n 次,但第二个 for 循环中的索引设置为 i。 //where n is the number elemen
我是一名优秀的程序员,十分优秀!