2016-01-20 27 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包)時,您需要配置日誌框架以打印此類/包的調試語句!