如何使customAppender像ConsoleAppender一样表现异步

时间:2015-12-05 08:11:31

标签: java spring java-ee logging log4j

// @元器件 公共类MyAppender扩展了AppenderSkeleton {

@Override
protected void append(LoggingEvent event) {
System.out.println("Peform Sending sns task here ........");

try {
    //Send to Sns or any other source
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
System.out.println("done sleeping");    
}

static{
    System.out.println("Loading MyAppender Class");
}

@Override
public void close() {
    // TODO Auto-generated method stub

}

@Override
public boolean requiresLayout() {
    // TODO Auto-generated method stub
    return false;
}

} // EOF MyAppender

公共类LoggingFilter扩展了OncePerRequestFilter {

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        final FilterChain filterChain) throws ServletException, IOException {


        filterChain.doFilter(request, response);


        System.out.println("Logging is Started From Filters >>>>>>>>>>>");

            logger.debug("This is my test Log Msg 1");
            logger.debug("This is my test Log Msg 2");
            logger.debug("This is my test Log Msg 3");
            logger.debug("This is my test Log Msg 4");
            logger.debug("This is my test Log Msg 5");

        System.out.println("Logging is Completed in Filters >>>>>>>>>>>");

} }

期望输出: 记录从过滤器开始 记录从过滤器

完成

在外部完成其他事情,但我的流程是顺序的

0 个答案:

没有答案