You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Benjamin Jaton <be...@gmail.com> on 2015/11/05 20:55:42 UTC
Log4j2 - HTML emails pattern
Hi,
I am using the SMTPAppender with a custom pattern:
"PatternLayout" : { "pattern" : "<a href='...'>%m</a><br/>" }
But the email is sent as text.
I saw that there is a HTMLLayout but it doesn't seem to accept a pattern?
How can I produce a custom HTML message?
Thanks!
Ben
Re: Log4j2 - HTML emails pattern
Posted by Gary Gregory <ga...@gmail.com>.
Ben:
What version of Log4j are you using?
Can you post you full config file please?
Gary
On Thu, Nov 5, 2015 at 11:55 AM, Benjamin Jaton <be...@gmail.com>
wrote:
> Hi,
>
> I am using the SMTPAppender with a custom pattern:
> "PatternLayout" : { "pattern" : "<a href='...'>%m</a><br/>" }
>
> But the email is sent as text.
>
> I saw that there is a HTMLLayout but it doesn't seem to accept a pattern?
>
> How can I produce a custom HTML message?
>
> Thanks!
> Ben
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: Log4j2 - HTML emails pattern
Posted by Benjamin Jaton <be...@gmail.com>.
You mean just put HTML in the pattern directly?
You need to content type of the email to be set to text/html, other you
would just see the HTML code in the email.
On Tue, Nov 10, 2015 at 9:21 PM, Matt Sicker <bo...@gmail.com> wrote:
> It seems abusive, but couldn't you just use the PatternLayout and
> interweave HTML?
> On 10 November 2015 at 11:57, Benjamin Jaton <be...@gmail.com>
> wrote:
>
> > I am trying to use a logger in order to send "alerts" to the user. So for
> > me 1 log = 1 email (hence LOG4J2-1071).
> > I use the regular PatternLayout to produce a simple but full HTML page
> with
> > my alert email template.
> >
> > For the HTMLLayout to be usable, it would have to allow to customize the
> > pattern, header and footer.
> > Bonus points if we could use the MDC in the email subject.
> >
> > Ben
> >
> > On Mon, Nov 9, 2015 at 11:48 AM, Gary Gregory <ga...@gmail.com>
> > wrote:
> >
> > > Ben,
> > >
> > > Is there a way the current HTML layout could be customized to be better
> > > suited to your use-case?
> > >
> > > Gary
> > >
> > > On Mon, Nov 9, 2015 at 11:09 AM, Benjamin Jaton <
> > benjamin.jaton@gmail.com>
> > > wrote:
> > >
> > > > Thanks the feedback.
> > > > I found that the easiest way to achieve this was to have the
> > > PatternLayout
> > > > class support to set the contentType to "text/html".
> > > > Then one can write HTML directly in the pattern.
> > > >
> > > > Thanks again,
> > > > Ben
> > > >
> > > > On Mon, Nov 9, 2015 at 6:51 AM, Remko Popma <re...@gmail.com>
> > > wrote:
> > > >
> > > > > Ben,
> > > > >
> > > > > The built-in HTML layout (
> > > > >
> > > >
> > >
> >
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html
> > > > )
> > > > > does not support much customization.
> > > > >
> > > > > It sounds like you may want to create a custom layout and specify
> > that
> > > > > layout with the SMTP appender.
> > > > >
> > > > > This manual page may be a good place to get started:
> > > > > http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
> > > > >
> > > > > Best regards,
> > > > > Remko
> > > > >
> > > > > > On 2015/11/06, at 4:55, Benjamin Jaton <benjamin.jaton@gmail.com
> >
> > > > wrote:
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I am using the SMTPAppender with a custom pattern:
> > > > > > "PatternLayout" : { "pattern" : "<a href='...'>%m</a><br/>" }
> > > > > >
> > > > > > But the email is sent as text.
> > > > > >
> > > > > > I saw that there is a HTMLLayout but it doesn't seem to accept a
> > > > pattern?
> > > > > >
> > > > > > How can I produce a custom HTML message?
> > > > > >
> > > > > > Thanks!
> > > > > > Ben
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > <http://www.manning.com/bauer3/>
> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > Spring Batch in Action <http://www.manning.com/templier/>
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> > >
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
Re: Log4j2 - HTML emails pattern
Posted by Matt Sicker <bo...@gmail.com>.
It seems abusive, but couldn't you just use the PatternLayout and
interweave HTML?
On 10 November 2015 at 11:57, Benjamin Jaton <be...@gmail.com>
wrote:
> I am trying to use a logger in order to send "alerts" to the user. So for
> me 1 log = 1 email (hence LOG4J2-1071).
> I use the regular PatternLayout to produce a simple but full HTML page with
> my alert email template.
>
> For the HTMLLayout to be usable, it would have to allow to customize the
> pattern, header and footer.
> Bonus points if we could use the MDC in the email subject.
>
> Ben
>
> On Mon, Nov 9, 2015 at 11:48 AM, Gary Gregory <ga...@gmail.com>
> wrote:
>
> > Ben,
> >
> > Is there a way the current HTML layout could be customized to be better
> > suited to your use-case?
> >
> > Gary
> >
> > On Mon, Nov 9, 2015 at 11:09 AM, Benjamin Jaton <
> benjamin.jaton@gmail.com>
> > wrote:
> >
> > > Thanks the feedback.
> > > I found that the easiest way to achieve this was to have the
> > PatternLayout
> > > class support to set the contentType to "text/html".
> > > Then one can write HTML directly in the pattern.
> > >
> > > Thanks again,
> > > Ben
> > >
> > > On Mon, Nov 9, 2015 at 6:51 AM, Remko Popma <re...@gmail.com>
> > wrote:
> > >
> > > > Ben,
> > > >
> > > > The built-in HTML layout (
> > > >
> > >
> >
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html
> > > )
> > > > does not support much customization.
> > > >
> > > > It sounds like you may want to create a custom layout and specify
> that
> > > > layout with the SMTP appender.
> > > >
> > > > This manual page may be a good place to get started:
> > > > http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
> > > >
> > > > Best regards,
> > > > Remko
> > > >
> > > > > On 2015/11/06, at 4:55, Benjamin Jaton <be...@gmail.com>
> > > wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > I am using the SMTPAppender with a custom pattern:
> > > > > "PatternLayout" : { "pattern" : "<a href='...'>%m</a><br/>" }
> > > > >
> > > > > But the email is sent as text.
> > > > >
> > > > > I saw that there is a HTMLLayout but it doesn't seem to accept a
> > > pattern?
> > > > >
> > > > > How can I produce a custom HTML message?
> > > > >
> > > > > Thanks!
> > > > > Ben
> > > >
> > >
> >
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> >
>
--
Matt Sicker <bo...@gmail.com>
Re: Log4j2 - HTML emails pattern
Posted by Benjamin Jaton <be...@gmail.com>.
I am trying to use a logger in order to send "alerts" to the user. So for
me 1 log = 1 email (hence LOG4J2-1071).
I use the regular PatternLayout to produce a simple but full HTML page with
my alert email template.
For the HTMLLayout to be usable, it would have to allow to customize the
pattern, header and footer.
Bonus points if we could use the MDC in the email subject.
Ben
On Mon, Nov 9, 2015 at 11:48 AM, Gary Gregory <ga...@gmail.com>
wrote:
> Ben,
>
> Is there a way the current HTML layout could be customized to be better
> suited to your use-case?
>
> Gary
>
> On Mon, Nov 9, 2015 at 11:09 AM, Benjamin Jaton <be...@gmail.com>
> wrote:
>
> > Thanks the feedback.
> > I found that the easiest way to achieve this was to have the
> PatternLayout
> > class support to set the contentType to "text/html".
> > Then one can write HTML directly in the pattern.
> >
> > Thanks again,
> > Ben
> >
> > On Mon, Nov 9, 2015 at 6:51 AM, Remko Popma <re...@gmail.com>
> wrote:
> >
> > > Ben,
> > >
> > > The built-in HTML layout (
> > >
> >
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html
> > )
> > > does not support much customization.
> > >
> > > It sounds like you may want to create a custom layout and specify that
> > > layout with the SMTP appender.
> > >
> > > This manual page may be a good place to get started:
> > > http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
> > >
> > > Best regards,
> > > Remko
> > >
> > > > On 2015/11/06, at 4:55, Benjamin Jaton <be...@gmail.com>
> > wrote:
> > > >
> > > > Hi,
> > > >
> > > > I am using the SMTPAppender with a custom pattern:
> > > > "PatternLayout" : { "pattern" : "<a href='...'>%m</a><br/>" }
> > > >
> > > > But the email is sent as text.
> > > >
> > > > I saw that there is a HTMLLayout but it doesn't seem to accept a
> > pattern?
> > > >
> > > > How can I produce a custom HTML message?
> > > >
> > > > Thanks!
> > > > Ben
> > >
> >
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
Re: Log4j2 - HTML emails pattern
Posted by Gary Gregory <ga...@gmail.com>.
Ben,
Is there a way the current HTML layout could be customized to be better
suited to your use-case?
Gary
On Mon, Nov 9, 2015 at 11:09 AM, Benjamin Jaton <be...@gmail.com>
wrote:
> Thanks the feedback.
> I found that the easiest way to achieve this was to have the PatternLayout
> class support to set the contentType to "text/html".
> Then one can write HTML directly in the pattern.
>
> Thanks again,
> Ben
>
> On Mon, Nov 9, 2015 at 6:51 AM, Remko Popma <re...@gmail.com> wrote:
>
> > Ben,
> >
> > The built-in HTML layout (
> >
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html
> )
> > does not support much customization.
> >
> > It sounds like you may want to create a custom layout and specify that
> > layout with the SMTP appender.
> >
> > This manual page may be a good place to get started:
> > http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
> >
> > Best regards,
> > Remko
> >
> > > On 2015/11/06, at 4:55, Benjamin Jaton <be...@gmail.com>
> wrote:
> > >
> > > Hi,
> > >
> > > I am using the SMTPAppender with a custom pattern:
> > > "PatternLayout" : { "pattern" : "<a href='...'>%m</a><br/>" }
> > >
> > > But the email is sent as text.
> > >
> > > I saw that there is a HTMLLayout but it doesn't seem to accept a
> pattern?
> > >
> > > How can I produce a custom HTML message?
> > >
> > > Thanks!
> > > Ben
> >
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: Log4j2 - HTML emails pattern
Posted by Benjamin Jaton <be...@gmail.com>.
Thanks the feedback.
I found that the easiest way to achieve this was to have the PatternLayout
class support to set the contentType to "text/html".
Then one can write HTML directly in the pattern.
Thanks again,
Ben
On Mon, Nov 9, 2015 at 6:51 AM, Remko Popma <re...@gmail.com> wrote:
> Ben,
>
> The built-in HTML layout (
> https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html)
> does not support much customization.
>
> It sounds like you may want to create a custom layout and specify that
> layout with the SMTP appender.
>
> This manual page may be a good place to get started:
> http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
>
> Best regards,
> Remko
>
> > On 2015/11/06, at 4:55, Benjamin Jaton <be...@gmail.com> wrote:
> >
> > Hi,
> >
> > I am using the SMTPAppender with a custom pattern:
> > "PatternLayout" : { "pattern" : "<a href='...'>%m</a><br/>" }
> >
> > But the email is sent as text.
> >
> > I saw that there is a HTMLLayout but it doesn't seem to accept a pattern?
> >
> > How can I produce a custom HTML message?
> >
> > Thanks!
> > Ben
>
Re: Log4j2 - HTML emails pattern
Posted by Remko Popma <re...@gmail.com>.
Ben,
The built-in HTML layout (https://logging.apache.org/log4j/2.x/log4j-core/xref/org/apache/logging/log4j/core/layout/HtmlLayout.html) does not support much customization.
It sounds like you may want to create a custom layout and specify that layout with the SMTP appender.
This manual page may be a good place to get started: http://logging.apache.org/log4j/2.x/manual/extending.html#Layouts
Best regards,
Remko
> On 2015/11/06, at 4:55, Benjamin Jaton <be...@gmail.com> wrote:
>
> Hi,
>
> I am using the SMTPAppender with a custom pattern:
> "PatternLayout" : { "pattern" : "<a href='...'>%m</a><br/>" }
>
> But the email is sent as text.
>
> I saw that there is a HTMLLayout but it doesn't seem to accept a pattern?
>
> How can I produce a custom HTML message?
>
> Thanks!
> Ben