I would like to use log4j and send email in HTML format (Using 开发者_如何学GoSMTP Appender). Is it possible in log4j out of the box.
If so please point me to right examples
Logback provides a Layout that formats the logs as HTML. Combining that with an SMTPAppender would send email in HTML format.
http://logback.qos.ch/manual/layouts.html#ClassicHTMLLayout
Direct quote from the page:
The HTMLLayout is often used in conjunction with SMTPAppender so that outgoing email is pleasantly formatted in HTML.
You could even take the source code and modify it, pretty easily, to suit your needs.
http://logback.qos.ch/xref/ch/qos/logback/classic/html/HTMLLayout.html
They provide the following code to initilaize the appender:
<appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%relative%thread%mdc%level%class%msg</pattern>
</layout>
<From>sender.email@domain.net</From>
<SMTPHost>mail.domain.net</SMTPHost>
<Subject>LastEvent: %class - %msg </Subject>
<To>destination.email@domain.net</To>
</appender>
I hope that helps in some way,
-gMale
精彩评论