3 Replies Latest reply on Nov 3, 2009 11:49 AM by peterj

    Writing a log4j email service

    fuchs

      Hello,
      i am using the jboss-portal-2.7.2 bundle and i like to know, how i could write an email service, to be informed, if the server throws any ERRORs.

      what i know is that i have to edit the jboss-log4j.xml:

      <appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
       <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
       <param name="Threshold" value="ERROR"/>
       <param name="To" value="myemail@gmail.com"/>
       <param name="From" value="nobody@myhost.domain.com"/>
       <param name="Subject" value="JBoss Sever Errors"/>
       <param name="SMTPHost" value="localhost"/>
       <param name="BufferSize" value="10"/>
       <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
       </layout>
       </appender>
      
      
       <root>
       <appender-ref ref="CONSOLE"/>
       <appender-ref ref="FILE"/>
       <appender-ref ref="SMTP"/>
       </root>
      


      do i have to edit the jboss-service.xml in the jboss-portal.sar also?
      have i something missed?

      Thanks for helping!

        • 1. Re: Writing a log4j email service
          peterj

          Defining an SMTPAppender should be all that you need. But you must ensure that the SMTP info you provide leads to an SMTP server. Is there one running on your system (your config has 'localhost' as the SMTPHost)? When I tried this a while back I used the SMTP host provided by by ISP and that worked.

          • 2. Re: Writing a log4j email service
            fuchs

            thanks for your fast response.
            but still it doesnt work.
            whats about the "from" field? Must this address: nobody@myhost.domain.com be a valid address ?
            do i have to define a category, like :

            <category name="org.jboss.portal">
             <priority value="ERROR" />
             <appender-ref ref="SMTP" />
             </category>


            • 3. Re: Writing a log4j email service
              peterj

              I have always used a valid "from" field, even the log4j book I have is silent as to if the "from" address needs to be valid.

              You don't have to add the extra category - what you did earlier for root should be fine.

              The one thing I don't see for the SMTPAppender is authentication handling. I know that my ISP requires an account and a password to send email. But I cannot recall how I handled this when I set up the SMTPAppender before (and of course I no longer have that configuration).

              OK, I looked up the javadoc for SMTPAppender (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/net/SMTPAppender.html), there is a SMTPUsername and SMTPPassword parameter, which you can set using:

              <appender ...>
               ...
               <param name="SMTPUsername" value="xxx"/>
               <param name="SMTPPassword" value="xxx"/>
              </appender>


              The stupid book I have doesn't event mention these parameters, nor a few others that are available on SMTPAppender.