当一个包发布为release版本时候,日志的异常信息的堆栈信息不能明确到具体代码的行数,我们公司日志信息都集中在struts的action里面输出,我想了解下诸位的是怎么解决这个问题的。我现在维护项目就遇到这样的问题,一个方法比较长,报了一个错误,无法定位到具体行数,排除一个错误会浪费很长时时间,项目是老项目,有什么好的办法解决这个问题呢。

解决方案 »

  1.   

    public void printStackTrace(PrintStream s);
    public void printStackTrace(PrintWriter s);io写入文件吧。
      

  2.   

    把日志的调用栈信息都输入到日志上不就完了
    /**
     *
     * @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();
        }