2015-05-19 37 views
0

下午好,Log4J2廠錯誤嘗試使用SMTP追加程序

當我嘗試使用SMTP追加程序時,我得到一個奇怪的錯誤在控制檯中。加載XML文件時出現此錯誤,因爲它不會通過除stdout之外的任何輸出流進行記錄。 appender的內容如下(我確認錯誤在這個XML塊中)。我已刪除我們的服務器信息。

<SMTP name="Mailer"> 
    <Subject>[ERROR] (software name) on ${hostName} has thrown a fatal error</Subject> 
    <To>(a valid email in the form of [email protected])</To> 
    <From>(a valid email in the form of [email protected])</From> 
    <SMTPHost>(The Internal IP address of a server in the form of 192.168.0.1)</SMTPHost> 
    <SMTPPort>587</SMTPPort> 
    <BufferSize>512</BufferSize> 
</SMTP> 

無論它是在記錄中引用,我立即收到以下錯誤一旦運行該程序,並從日誌管理器運行getLogger。我已經刪除了一些文件名,並用粗略描述了該文件在這一點上的作用來替換它們。

2015-05-19 19:08:18,812 ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.appender.SmtpAppender for element SMTP. java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:137) at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:766) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:706) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:698) at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:358) at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:161) at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:361) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:426) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:442) at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41) at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:426) at (Our Log Interface Class, which essentially just returns the log passed by the Apache log manager) at (The global variable definition file, the first method to use getLogger) at (The main method for our software, where the globals are loaded) Caused by: java.lang.NoSuchMethodError: javax.mail.Session.setProtocolForAddress(Ljava/lang/String;Ljava/lang/String;)V at org.apache.logging.log4j.core.net.SmtpManager$SMTPManagerFactory.createManager(SmtpManager.java:325) at org.apache.logging.log4j.core.net.SmtpManager$SMTPManagerFactory.createManager(SmtpManager.java:299) at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:71) at org.apache.logging.log4j.core.net.SmtpManager.getSMTPManager(SmtpManager.java:124) at org.apache.logging.log4j.core.appender.SmtpAppender.createAppender(SmtpAppender.java:142) ... 21 more

2015-05-19 19:08:18,814 ERROR Null object returned for SMTP in Appenders. 2015-05-19 19:08:18,819 ERROR Unable to locate appender Mailer for logger fatalerror

的配置的詳細信息是正確的(我知道這是一個有效的IP等) - 他們的log4j 1.工作錯誤日誌告訴我幾乎一無所知的錯誤,所以我希望有人聽說過這之前。感謝大家!

+0

您需要將'$ {hostName}'更改爲'$ {sys:hostName}'。 –

+0

好,但實際上這不是我們的問題。這是該軟件使用的郵件API多年未更新。 –

回答

1

這是從你的堆棧跟蹤的重要線路:

Caused by: java.lang.NoSuchMethodError: javax.mail.Session.setProtocolForAddress(Ljava/lang/String;Ljava/lang/String;)V

setProtocolForAddress method自1.4版本已經JavaMail的一部分,所以這個建議,我認爲您使用的是舊版本的JAR。如果是,請嘗試升級到更高版本。

+0

到底是什麼,謝謝。我認爲在我們的軟件中存在郵件功能並且從未想過檢查什麼時候圖書館最後一次更新(提示:它不是) –

0

請注意,log4j2有很多查找,而不僅僅是系統屬性。因此,您需要將${hostName}轉換爲${sys:hostName},並且如果您使用IP地址查找,這可能是問題的原因。 (嘗試硬編碼所有查找值以排除此可能性。)

+0

它實際上是一個過時的JavaMail版本,不過謝謝你的建議! –