2

I have been through lot of WildFly documentation in past day and so far I have failed to understand how a SMTP Handler could be added to WildFly logging sybsystem. This was very easy when JBoss used log4j but now there are hardly any documentation available.

Places I have already looked at: https://docs.jboss.org/author/display/WFLY8/Logging+Configuration

There is support of using a Custom Log handler. as mentioned jira https://issues.jboss.org/browse/AS7-1438 but are there any examples available? can log4j SMTP handler be used here?

Is this the best solution available? https://developer.jboss.org/wiki/CreatingACustomLoggingHandlerInJBOSSAs710Final

noone
  • 19,520
  • 5
  • 61
  • 76
Salman A. Kagzi
  • 3,833
  • 13
  • 45
  • 64

1 Answers1

4

How about this one with jboss-cli:

/subsystem=logging/custom-handler=LOG4J_SMTP:add( \
 class="org.apache.log4j.net.SMTPAppender", \
 module="org.apache.log4j", \
 formatter="%-5p [%c] (%t) %s%e", \
 level=INFO, \
 properties={ \
  From="jane.doe@gmail.example.com", \
  LocationInfo=true, \
  SMTPDebug=true, \
  SMTPHost="smtp.gmail.com", \
  SMTPPort=465, \
  SMTPProtocol="smtps", \
  SMTPUsername="jane.doe@gmail.example.com",  \
  SMTPPassword="***", \
  Subject="error mail subject", \
  To="jane.doe@icloud.example.com", \
  BufferSize=256 })

For configuration details see: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/net/SMTPAppender.html

Kohei Nozaki
  • 1,154
  • 1
  • 13
  • 36
  • This worked! Any idea if its possible to use Java Mail service configured in WildFly to send email? (Thus isolating all SMTP connection details into a single place) – Salman A. Kagzi Mar 10 '15 at 06:01
  • Good. I wish I could too, but I think it's impossible at the moment because there's no implementation of JNDI lookup in current SMTPAppender of log4j. the odd thing is that [it's resolved in the bug tracker](https://bz.apache.org/bugzilla/show_bug.cgi?id=35259) but I couldn't found any implementation in [the source code](http://grepcode.com/file/repo1.maven.org/maven2/log4j/log4j/1.2.17/org/apache/log4j/net/SMTPAppender.java?av=f). so we may need to implement a custom handler to achieve it. – Kohei Nozaki Mar 10 '15 at 11:02