3 Replies Latest reply on Dec 1, 2017 1:47 AM by johnsi george

    wildfly 10 mail logger

    johnsi george Newbie

      Hi,

      can one kindly redirect me to article / sample to send exception in log as mail from wildfly 10 server.

      below is the code tried in jboss 6

       

      <log4j-appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">

            <error-manager>

               <only-once/>

            </error-manager>

         <level name="ERROR"/>

      <properties>

               <property name="to">Provide to email address here</property>

               <property name="from">Provide from email address here</property>

               <property name="subject">XXX Error</property>

               <property name="SMTPHost">Provide host name of email</property>

                <property name="SMTPUsername">Provide user email id of host</property>

                 <property name="SMTPPassword">Provide password for the SMTPUsername</property>

               <property name="bufferSize">10</property>

             </properties>

      <formatter>

               <pattern-formatter pattern="%d %-5p  %m%n"/>

            </formatter>

         </log4j-appender>

        • 1. Re: wildfly 10 mail logger
          lukaszracon Newbie

          Try this:

                  <subsystem xmlns="urn:jboss:domain:logging:3.0">

                      <async-handler name="EMAIL">

                          <level name="ERROR"/>

                          <queue-length value="100"/>

                          <overflow-action value="discard"/>

                          <subhandlers>

                              <handler name="emailHandler"/>

                          </subhandlers>

                      </async-handler>

                      <custom-handler name="emailHandler" class="org.apache.log4j.net.SMTPAppender" module="org.apache.log4j">

                          <level name="ERROR"/>

                          <formatter>

                              <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>

                          </formatter>

                          <properties>

                              <property name="BufferSize" value="512"/>

                              <property name="To" value="app-exception@example.com"/>

                              <property name="From" value="sysadmin@example.com"/>

                              <property name="Subject" value="[${jboss.node.name}] Application Error"/>

                              <property name="SMTPHost" value="localhost"/>

                          </properties>

                      </custom-handler>

                      <root-logger>

                          <level name="WARN"/>

                          <handlers>

                              <handler name="EMAIL"/>

                          </handlers>

                      </root-logger>

                  </subsystem>

          • 2. Re: wildfly 10 mail logger
            James Perkins Master

            I'd suggest using CLI instead of editing the XML. Something like this should achieve the same results and not require shutting down WildFly and restarting it.

            /subsystem=logging/custom-handler=emailHandler:add(class="org.apache.log4j.net.SMTPAppender", module="org.apache.log4j", level=ERROR, named-formatter=PATTERN, properties={BufferSize="512", To="app-exception@example.com", From="sysadmin@example.com", Subject="[${jboss.node.name}] Application Error", SMTPHost="localhost"})
            /subsystem=logging/async-handler=async:add(queue-length=100, overflow-action=discard, handlers=[emailHandler])
            /subsystem=logging/root-logger=ROOT:add-handler(name=async)
            

             

            --

            James R. Perkins

            • 3. Re: wildfly 10 mail logger
              johnsi george Newbie

              Thank you.Learned a new stuff.