我试图用log4j保存所有身份验证事件,我已经创建了这个java类:
@Component(value = "authListener")
public class AuthenticationEventListener implements ApplicationListener<AbstractAuthenticationEvent> {
private static Logger logger = Logger.getLogger(AuthenticationEventListener.class);
public void onApplicationEvent(AbstractAuthenticationEvent authenticationEvent) {
if (authenticationEvent instanceof InteractiveAuthenticationSuccessEvent) {
return;
}
Authentication authentication = authenticationEvent.getAuthentication();
String auditMessage = "Utilisateur " + authentication.getName() + " login avec succés: " + authentication.isAuthenticated();
logger.info(auditMessage);
}
}
我正在使用spring Mvc和spring安全性,我的问题是如何使此日志工作(配置)以及在哪里找到日志记录数据?我不知道我的工作是否正确,我需要你的建议。谢谢你的帮助。
这取决于您使用的Logger (import中包含的内容)。在此基础上,以某种方式配置它们。
例如,您可以使用Log4J,您可以在属性文件中指定日志文件的位置:Log4J example如示例中所述,创建文件log4j。属性在src/main/resource中,在那里你可以指定你想要从日志输出的文件:log4j.appender.file.File=C:\log4j-application.log