0

Bafflingly, there's no SMTP implementation out of the box. How is it not a basic feature?

Tried adding a custom handler type MailHandler, but I get stuck setting the properties. It seems a good chunk of them (such as the mail server's hostname) are defined by a Properties object in the MailHandler's constructor, but I don't know how to set that up in the custom handler's properties, as it relies on setters instead.

Also tried registering a log4j SMTPAppender. Although this works surprisingly well, and the documentation claims it's legal, Wildfly threatens to bite:

16:49:21,090 WARN  [org.jboss.as.logging] (management-handler-thread - 3) WFLYLOG0099: Usage of a log4j appender (org.apache.log4j.net.SMTPAppender) found in a custom-handler. Support for using appenders as custom handlers has been deprecated and will be removed in a future release.

Am I naive in thinking I will be able to pull this off without coding my own generic mail handler, or deferring the mail stuff to syslog?

Yd Ahhrk
  • 103
  • 2
  • Most sysadmins would consider logging to e-mail a ridiculous concept. Many events in log files are only a single line and getting a 100'000+ crappy e-mails per hour with a single line as the body (and maybe an occasional longer message with a stack trace) will definitely explode my inbox. - Let your monitoring system send an email instead. – HBruijn Aug 11 '22 at 13:14
  • I'm talking about `FATAL`s (and possibly `ERROR`s) only. I'm not trying to dump the entire `INFO` cacophony into e-mails. – Yd Ahhrk Aug 11 '22 at 14:19

1 Answers1

1

You'd have to develop your own MailHandler or SmtpHandler. WildFly does not currently provide one because there is not a good way to configure one. Also as noted in the comments of the question, it's not really the ideal way to be notified of errors.

The log4j SmtpAppender will work until WildFly 27 where log4j support was removed.

The JUL MailHandler won't work as WildFly needs to be able to use setters to set properties.

  • The comment noted why it's a bad idea to dump the entire log file into an inbox, not why it's a bad idea to fetch very rare and relevant error messages into an inbox... – Yd Ahhrk Aug 11 '22 at 16:52
  • IMO it's generally best to send those logs to some kind of log aggregator and have another means of notification. That said, for WildFly logging starts before the server can configuration a SMTP session. You'd have to configure a SMTP session from scratch before the handler would work. – James R. Perkins Aug 11 '22 at 18:41