2009. 1. 8. 16:06

printStackTrace를 Log4j에 출력하기




package com.qnsolv.wipi.exception;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ExceptionUtil
{
 Log log = null;
 
 
 public ExceptionUtil( Object obj)
 {
  log = LogFactory.getLog(obj.getClass().getName());
 }
 public ExceptionUtil()
 {
  log = LogFactory.getLog(this.getClass().getName());
 }
 public void writePrintStckTrace(Exception e)
 {
  writePrintStckTrace(e, "");
 }
 
 public void writePrintStckTrace(Exception e, String MIN)
 {
  try
  {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   PrintStream pinrtStream = new PrintStream(new ByteArrayOutputStream());
   e.printStackTrace(pinrtStream);
   String stackTraceString = out.toString();
   log.error("MIN=" + MIN + ":" + stackTraceString.toString());
  }
  catch (Exception e2)
  {
  }
 }
}