2017-06-27 87 views
0

我對如何在Apache Log4J中使用logger.throwing以使用特定日誌級別記錄異常存在一些困惑。Log4j logger.throwing無法設置日誌級別

記錄儀是org.apache.logging.log4j.Logger

的實例,這工作得很好:

return logger.throwing(new Exception("Message")); 

這是行不通的。爲什麼?

return logger.throwing(Level.DEBUG, new Exception("Message")); 

以下是編譯器顯示錯誤:

[javac]  return logger.throwing(Level.DEBUG, new Exception("Message")); 
[javac]        ^
[javac]  method Logger.<T#1>throwing(org.apache.logging.log4j.Level,T#1) is not applicable 
[javac]  (cannot infer type-variable(s) T#1 
[javac]   (argument mismatch; org.apache.log4j.Level cannot be converted to org.apache.logging.log4j.Level)) 
[javac]  method Logger.<T#2>throwing(T#2) is not applicable 
[javac]  (cannot infer type-variable(s) T#2 
[javac]   (actual and formal argument lists differ in length)) 
[javac] where T#1,T#2 are type-variables: 
[javac]  T#1 extends Throwable declared in method <T#1>throwing(org.apache.logging.log4j.Level,T#1) 
[javac]  T#2 extends Throwable declared in method <T#2>throwing(T#2) 
+2

'org.apache.log4j.Level無法轉換爲org.apache.logging.log4j.Level'指定Level的完整軟件包名稱。 – Compass

+0

@Compass是的,這是正確的答案。謝謝。 – leontp587

回答