求助:日志的问题

J2EE 码拜 9年前 (2015-05-10) 707次浏览 0个评论
 

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

30分
public void printStackTrace(PrintStream s);
public void printStackTrace(PrintWriter s);

io写入文件吧。

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


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求助:日志的问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!