you have to pay attention not to let your log4j smtp logger append in
"sync" mode - your system will stall, until the logging message has been
sent (which could be a few seconds, depending how you send your mail).
your have to use an async logger. this is an example configuration i use
in my system. only "error" level logging events will be sent by mail,
all other stuff is logged to a regular file:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN"

"http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd";>

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>

    <appender name="file" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="application.log" />
        <param name="Append" value="true" />
        <param name="MaxBackupIndex" value="10" />
        <param name="MaxFileSize" value="100MB" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601}:
application %p [%c] -> %m (%X{requestedUrl})%n" />
        </layout>
    </appender>

    <appender name="mail" class="org.apache.log4j.net.SMTPAppender">
        <param name="BufferSize" value="1" />
        <param name="SMTPHost" value="smtphost" />
        <param name="SMTPUsername" value="smtpuser" />
        <param name="SMTPPassword" value="password" />
        <param name="From" value="m...@sender.com" />
        <param name="To" value="m...@receipient.com" />
        <param name="Subject" value="Logging message application" />
        <param name="threshold" value="error" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601}:
application %p [%c] -> %m (%X{requestedUrl})%n" />
        </layout>
    </appender>

    <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
        <param name="BufferSize" value="100" />
        <appender-ref ref="mail" />
    </appender>

    <logger name="de.my.application">
        <level value="DEBUG" />
    </logger>

    <logger name="com.other.application">
        <level value="DEBUG" />
    </logger>

    <logger name="some.third.party.lib">
        <level value="WARN"></level>
    </logger>

    <root>
        <priority value="warn" />
        <appender-ref ref="ASYNC" />
        <appender-ref ref="file" />
    </root>

</log4j:configuration>


%X{requestedUrl} is a MDC log4j variable and i store the requested URL
in it. it helps a lot when you have to debug requests (often crawlers
and bots send requests with invalid characters in the url - this way you
can easily detect this). to store the requested url in the MDC i
implemented a wrapper around the TapestryFilter which stores the
requested url before the filtered request get's handled by tapestry.


    private static final Logger log       =
LoggerFactory.getLogger(MyFilter.class);

    private TapestryFilter      tapFilter = null;

    @Override
    public final void doFilter(ServletRequest request, ServletResponse
response, FilterChain chain) throws IOException,

                           ServletException {
        try {
            MDC.put("requestedUrl", this.getRequestedUrl(request));
            if (this.tapFilter != null) {
                this.tapFilter.doFilter(request, response, chain);
            }
            else {
                chain.doFilter(request, response);
            }
        }
        finally {
            MDC.clear();
        }
    }

    private String getRequestedUrl(ServletRequest request) {
        try {
            StringBuilder buffer = new StringBuilder();
            if (request instanceof HttpServletRequest) {
                HttpServletRequest httpServletRequest =
(HttpServletRequest) request;
                buffer.append(httpServletRequest.getRequestURL());
            }
            return buffer.toString();
        }
        catch (Exception exception) {
            return null;
        }
    }

    @Override
    public final void destroy() {
        if (this.tapFilter != null) {
            this.tapFilter.destroy();
        }
    }

    @Override
    public final void init(FilterConfig filterConfig) throws
ServletException {
        log.debug("Initializing Tapestry filter");
        this.tapFilter = new TapestryFilter();
        this.tapFilter.init(filterConfig);
        log.debug("Tapestry Filter initialized!");
    }




Am 12.05.2012 14:51, schrieb Bob Harner:
> You couldd also have the logging system send the emails. Log4j can handle
> this quite easily.
> On May 11, 2012 7:35 AM, "Dmitry Gusev" <dmitry.gu...@gmail.com> wrote:
> 
>> Try this:
>>
>> http://tapestry.apache.org/overriding-exception-reporting.html
>>
>> On Fri, May 11, 2012 at 3:21 PM, jeczmien <jeczm...@podgorska.ddns.info
>>> wrote:
>>
>>> I need advice how to execute my code during tapestry exception handling.
>>>
>>>
>>> Current:
>>> 1. Something wrong has happen and tapestry shows exception page
>>> 2. error is logged in container' log
>>>
>>> My use case:
>>> 1. Something wrong has happen and tapestry shows exception page
>>> 2. error is logged in container' log
>>> 3. my method sends email notification to system operator containing
>>> exception log, or eventually exception page generated when application
>>> PRODUCTION_MODE is false.
>>>
>>> is there any contributeXXXX method for this?
>>>
>>> --
>>> View this message in context:
>>>
>> http://tapestry.1045711.n5.nabble.com/Joining-tapestry-exception-handling-tp5702797.html
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>>
>>
>>
>> --
>> Dmitry Gusev
>>
>> AnjLab Team
>> http://anjlab.com
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to