Reputation: 273
I started using Log4j2 on the system i am currently developing. And I encountered some problems.
here is my log4j2.properties file.
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
Here is the login method where i tried to test logging.
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;
}
The RollingFile doesn't seem to work. It creates a log file named beo.logs but it's also empty. Is there something wrong with my configuration?
Upvotes: 1
Views: 2714
Reputation: 9141
Your Logger name is shown as being somepackage.NavigationController. Surely the package it is in is not org.apache.logging.log4j.core.appender.rolling, which is the only Logger you have configured to go to the RollingFileAppender. I suspect you really want to use the package name of NavigationController.
Upvotes: 4