简体   繁体   English

Log4J2:在 log4j2.properties 文件中定义自定义级别

[英]Log4J2: define custom level in log4j2.properties file

this is my log4j2.properties:这是我的 log4j2.properties:

rootLogger.level = ALL

customLevels = V
customLevel.V.name = VERBOSE
customLevel.V.intLevel = 525

property.filename = trace.log
property.msgcolor = FATAL=BG_Yellow Red Bright, ERROR=Red, WARN=Yellow Bold, INFO=Green, DEBUG=BG_Magenta Yellow, TRACE=blue

appenders = R, console

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss,SSS} %highlight{%level}{${msgcolor}} %c{1}:%L]: %highlight{%msg}{${msgcolor}}%style{%n}{Default Normal}%throwable

appender.R.type = RollingFile
appender.R.name = File
appender.R.fileName = ${filename}
appender.R.filePattern = ${filename}.%d{yyyy-MM-dd}
appender.R.layout.type = PatternLayout
appender.R.layout.disableAnsi = true
appender.R.layout.noConsoleNoAnsi = true
appender.R.layout.pattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n
appender.R.policies.type = Policies
appender.R.policies.size.type = SizeBasedTriggeringPolicy
appender.R.policies.size.size = 20MB

rootLogger.appenderRefs = R, console

rootLogger.appenderRef.console.ref = STDOUT
rootLogger.appenderRef.R.ref = File

I expect that following code我希望下面的代码

customLevels = V
customLevel.V.name = VERBOSE
customLevel.V.intLevel = 525

add a new custom level named VERBOSE and with intLevel value set to 525, but it doesn't take any effects.添加一个名为 VERBOSE 的新自定义级别,并将 intLevel 值设置为 525,但它不会产生任何影响。 Why?为什么?

Use below in ur log4j2.properties: customLevel.VERBOSE=525在您的 log4j2.properties 中使用以下内容:customLevel.VERBOSE=525

I faced similar issue, it works when we configure log4j2 properties using xml file and having issue when we have these properties in log4j2.properties file.我遇到了类似的问题,当我们使用 xml 文件配置 log4j2 属性并且当我们在 log4j2.properties 文件中具有这些属性时出现问题时它会起作用。

solution for now would be as below, where you mention custom level name directly and remove customerLevel.v.name property.现在的解决方案如下,您可以在其中直接提及自定义级别名称并删除 customerLevel.v.name 属性。 This is until log4j2 fixes this issue.直到 log4j2 修复了这个问题。

simple solution: add below properties.简单的解决方案:添加以下属性。 for quick check, you can give the values as 1 instead for 525, 1 means it will log every time.为了快速检查,您可以将值设为 1 而不是 525,1 表示每次都会记录。

customLevels = VERBOSE customLevel.VERBOSE = 525 customLevels = VERBOSE customLevel.VERBOSE = 525

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将Log4j2 AsyncAppender与log4j2.properties一起使用 - Unable to use Log4j2 AsyncAppender with log4j2.properties 如何配置log4j2的log4j2.properties文件,使其具有带有2个不同级别的附加程序的记录器? - How to configure log4j2.properties file for log4j2 to have a logger with 2 appenders with different levels? Spring MVC + Log4j2 在未识别的类路径位置中定义 log4j2.properties 文件 - Spring MVC + Log4j2 defining log4j2.properties file in none class path location not identified Log4j2:如何在 log4j2.properties 文件中使用替换参数 - Log4j2: How to use replace parameter in log4j2.properties file 日志记录:在 Spring Boot 中使用 log4j2.properties 文件的 Log4j2 实现 - Logging : Log4j2 Implementation using log4j2.properties file in Spring Boot 自定义 appender 的 log4j2 属性文件 - log4j2 properties file for a custom appender 具有 log4j2.properties 的哨兵 - Sentry with log4j2.properties 在配置文件中定义自定义日志级别,并通过Java代码Log4J2访问它们 - Define Custom Log Level in Configuration file and Access them is Java Code, Log4J2 log4j2中的自定义日志级别问题 - Custom log level issue in log4j2 如何将 log4j.properties 文件转换为 log4j2.xml 或 log4j2.properties 文件 - How to convert the log4j.properties file to log4j2.xml or log4j2.properties file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM