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

时间:2018-01-11 00:09:49

标签: java log4j log4j2

这是我的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

我希望以下代码

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

添加一个名为VERBOSE的新自定义级别,并将intLevel值设置为525,但它不会产生任何效果。为什么呢?

1 个答案:

答案 0 :(得分:1)

在你的log4j2.properties中使用以下内容: customLevel.VERBOSE = 525