2017-06-27 8 views
0

特定のログレベルを使用して例外をログするために、Apache Log4Jでlogger.throwingを使用する方法について、いくつか混乱します。これは動作しませんLog4j logger.throwingはログレベルを設定できません

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

ロガーは、これが正常に動作しますorg.apache.logging.log4j.Logger

のインスタンスです。どうして?ここで

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

@コンパスはい、正解でした。ありがとうございました。 – leontp587

答えて

0

のLog4jでのレベルの2つの実装があります。古いLog4jメジャーバージョンのように、古いものはこれで動作しません。

Older implementation of org.apache.log4j.Level from 2012, for Log4j 1.2

The newer implementation is org.apache.logging.log4j.Level from 2017, for Log4j 2.X

可能な場合は、古いLevelへのすべての参照を削除し、新しい実装を使用するか、または完全なパッケージ名をハード宣言する。

関連する問題