2016-01-20 76 views
1

什么是设置为logging level == debug Spring Security的4.x的正确方法是什么?我正在使用slf4j/log4j弹簧安全日志记录级别调试不一致的行为

这里是我试过,log4j.properties:

... 
log4j.logger.org.springframework.security=DEBUG 

还与尝试:

log4j.category.org.springframework.security=DEBUG 

下返回false在AbstractAuthenticationProcessingFilter.successfulAuthentication

if (logger.isDebugEnabled()) { 
     logger.debug("Authentication success. Updating SecurityContextHolder to contain: " 
       + authResult); 
    } 

然而在SecurityContextPersistenceFilter的测试调试返回true,我可以看到调试输出:

if (debug) { 
    logger.debug("SecurityContextHolder now cleared, as request processing completed"); 
} 

控制台充满语句,如以下,表明日志记录级别确实debug

2016-01-20 12:10:34,849 DEBUG org.springframework.security.web.savedrequest.DefaultSavedRequest.propertyEquals(321): - pathInfo: both null (property equals) 
2016-01-20 12:10:34,849 DEBUG org.springframework.security.web.savedrequest.DefaultSavedRequest.propertyEquals(321): - queryString: both null (property equals) 

回答

0

我假设你使用自定义AbstractAuthenticationProcessingFilter,也许定制UsernamePasswordAuthenticationFilter?如果这是真的,那么我认为我可以解释这种行为。

它是(在GenericFilterBean每个子类以及)在AbstractAuthenticationProcessingFilter所使用的记录器logger是由GenericFilterBean的potected最终logger字段中提供。它是通过这个代码初始化:

/** Logger available to subclasses */ 
protected final Log logger = LogFactory.getLog(getClass()); 

,你可以看到,该记录器名称由Object.getClass()“定义”。因此,在AbstractAuthenticationProcessingFilter的每一个logger.debug(...)声明是由具体子类的记录器发布!

因此,当您有一个自定义的AuthenticationProcessingFilter(这可能不会抵制org.springframework.security包)时,您需要配置日志框架以打印此类/包的调试语句!