public void printStackTrace(PrintStream s); public void printStackTrace(PrintWriter s);io写入文件吧。
把日志的调用栈信息都输入到日志上不就完了 /** * * @author kayenzhang */ public class StringPrintWriter extends PrintWriter {
/** * Constructs a new instance. */ public StringPrintWriter() { super(new StringWriter()); } /** * Constructs a new instance using the specified initial string-buffer * size. * * @param initialSize an int specifying the initial size of the buffer. */ public StringPrintWriter(int initialSize) { super(new StringWriter(initialSize)); } /** * <p>Since toString() returns information *about* this object, we * want a separate method to extract just the contents of the * internal buffer as a String.</p> * * @return the contents of the internal string buffer */ public String getString() { flush(); return ((StringWriter) this.out).toString(); }
public void printStackTrace(PrintWriter s);io写入文件吧。
/**
*
* @author kayenzhang
*/
public class StringPrintWriter extends PrintWriter {
/**
* Constructs a new instance.
*/
public StringPrintWriter() {
super(new StringWriter());
} /**
* Constructs a new instance using the specified initial string-buffer
* size.
*
* @param initialSize an int specifying the initial size of the buffer.
*/
public StringPrintWriter(int initialSize) {
super(new StringWriter(initialSize));
} /**
* <p>Since toString() returns information *about* this object, we
* want a separate method to extract just the contents of the
* internal buffer as a String.</p>
*
* @return the contents of the internal string buffer
*/
public String getString() {
flush();
return ((StringWriter) this.out).toString();
}
} public static String buildStackTrace(
String msg,
Throwable e)
{
StringBuffer sb = new StringBuffer();
if(msg!=null){
sb.append(msg);
}
if(e!=null){
sb.append("详细信息:");
sb.append("\n");
StringPrintWriter pw = new StringPrintWriter();
e.printStackTrace(pw);
sb.append(pw.getString());
}
return sb.toString();
}