gpt4 book ai didi

java - Log4j2 RollingFile 不工作

转载 作者:行者123 更新时间:2023-11-30 03:04:01 25 4
gpt4 key购买 nike

我开始在我当前正在开发的系统上使用Log4j2。我遇到了一些问题。

这是我的log4j2.properties文件。

status = error
name = PropertiesConfig

filters = threshold

filter.threshold.type = ThresholdFilter
filter.threshold.level = debug

appenders = console, rolling, list

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.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${sys:catalina.home}/logs/beo.log
appender.rolling.filePattern = ${sys:catalina.home}/logs/beo-%d{MM-dd-yy-HH-mm-ss}-%i.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 2
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=100MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 5

appender.list.type = List
appender.list.name = List
appender.list.filters = threshold
appender.list.filter.threshold.type = ThresholdFilter
appender.list.filter.threshold.level = error

loggers = rolling

logger.rolling.name = org.apache.logging.log4j.core.appender.rolling
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRefs = rolling
logger.rolling.appenderRef.rolling.ref = RollingFile

rootLogger.level = info
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT

这是我尝试测试日志记录的登录方法

private static final Logger LOGGER = LogManager
.getLogger(NavigationController.class.getName());

@RequestMapping(value = { "/", "/login" })
public ModelAndView loginPage(
@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout) {

ModelAndView mv = new ModelAndView();

Authentication auth = SecurityContextHolder.getContext()
.getAuthentication();

if (!(auth instanceof AnonymousAuthenticationToken)) {
mv.setViewName("redirect:/auth/panel");

} else {
if (error != null) {
mv.addObject("error", "Invalid username and password!");
LOGGER.debug("debug");
LOGGER.info("info");
LOGGER.error("error");
LOGGER.warn("warning");
LOGGER.fatal("fatal");
}
mv.setViewName("login");
}

return mv;
}

enter image description here

RollingFile 似乎不起作用。它创建一个名为 beo.logs 的日志文件,但它也是空的。我的配置有问题吗?

最佳答案

您的记录器名称显示为 somepackage.NavigationController。当然,它所在的包不是 org.apache.logging.log4j.core.appender.rolling,它是您配置为转到 RollingFileAppender 的唯一 Logger。我怀疑您确实想使用 NavigationController 的包名称。

关于java - Log4j2 RollingFile 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35249605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com