我在com.example
中有一堆课程。我希望我的日志文件捕获调试日志记录,而我的控制台仅捕获信息。
我正在使用log4j2。
这是我的log4j2.properties文件。
name=PropertiesConfig
property.filename = logs
# configure both the appenders
# CONSOLE APPENDER
appender.console.type = console
appender.console.name = consoleAppender
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%t] %c{1} - %msg%n
# LOGFILE appender
appender.logfile.type = File
appender.logfile.name = logfileAppender
appender.logfile.fileName=extract.log
appender.logfile.layout.type=PatternLayout
appender.logfile.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
logger.example.name = com.example
logger.example.level = debug
logger.example.additivity = true
logger.example.appenderRef.logfile.ref = logfileAppender
logger.example.appenderRef.console.ref = consoleAppender
# configure the loggers, starting from the root logger.
rootLogger.level = info
要同时调试的日志。
我尝试这个...
name=PropertiesConfig
property.filename = logs
# configure both the appenders
# CONSOLE APPENDER
appender.console.type = console
appender.console.name = consoleAppender
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] [%t] %c{1} - %msg%n
# LOGFILE appender
appender.logfile.type = File
appender.logfile.name = logfileAppender
appender.logfile.fileName=extract.log
appender.logfile.layout.type=PatternLayout
appender.logfile.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
logger.example.name = com.example
logger.example.level = debug
logger.example.additivity = true
logger.example.appenderRef.logfile.ref = logfileAppender
logger.info.name = com.example
logger.info.level = info
logger.info.additivity = true
logger.info.appenderRef.console.ref = consoleAppender
# configure the loggers, starting from the root logger.
rootLogger.level = info
但是随后没有任何日志记录到控制台。
有什么想法吗?
答案 0 :(得分:0)
我也遇到了这个问题,当我添加时
rootLogger.appenderRef.console.ref=consoleAppender
rootLogger.appenderRef.rolling.ref=RollingFile
在我的log4j2末尾。好了consoleAppender和RollingFile是appender.console.name
和appender.rolling.name
的名称
这是我的log4j2 configure的结尾:
loggers=console, rolling
logger.console.name=console
logger.console.level=info
logger.console.additivity=false
logger.console.appenderRef.console.ref=consoleAppender
logger.rolling.name=com.viking
logger.rolling.level=info
logger.rolling.additivity=false
logger.rolling.appenderRef.rolling.ref=RollingFile
rootLogger.level=info
rootLogger.additivity=false
rootLogger.appenderRef.console.ref=consoleAppender
rootLogger.appenderRef.rolling.ref=RollingFile