如何把控制台输出的完整错误信息保存到文本?


控制台输出的错误信息

[INFO ] [09:10:08] org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl - HHH000010: On release of batch it still contained JDBC statements
[WARN ] [09:10:08] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 23505
[ERROR] [09:10:08] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - 批次处理 0 insert into cattagb_page (btname, burl, bvid, commentnums, curl, imgpath, jianjie, paiming, popularity, productnums, supercurlkey, turl, userdislike, usergrade, userlike, tburl) values ('....') 被中止,呼叫 getNextException 以取得原因。
[WARN ] [09:10:08] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 23505
[ERROR] [09:10:08] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - 错误: 重复键违反唯一约束"uk_ex9kef7svstkgntmfy2vh5emn"
  详细:键值"(turl, burl)=(laVjN, ChsfT)" 已经存在
[ERROR] [09:10:08] org.hibernate.engine.jdbc.batch.internal.BatchingBatch - HHH000315: Exception executing batch [could not execute batch]
org.hibernate.exception.ConstraintViolationException: could not execute batch
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:132)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.doExecuteBatch(BatchingBatch.java:111)
at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.execute(AbstractBatchImpl.java:163)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.getBatch(JdbcCoordinatorImpl.java:206)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3102)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3587)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:103)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:453)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:345)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
at zyme.tools.hibernate.MyHibernateUtil.oneThreadCheckThanSaveAllUpgraded(MyHibernateUtil.java:244)
at threads.save.SaveThread.savebegin(SaveThread.java:37)
at threads.save.SaveThread.run(SaveThread.java:31)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.sql.BatchUpdateException: 批次处理 0 insert into cattagb_page (btname, burl, bvid, commentnums, curl, imgpath, jianjie, paiming, popularity, productnums, supercurlkey, turl, userdislike, usergrade, userlike, tburl) values ('....') 被中止,呼叫 getNextException 以取得原因。
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2762)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1891)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:405)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2909)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1135)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:123)
... 18 more


报错的时候通过下面的代码保存的错误信息到文本.

catch (Exception e)
             {
             
             
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              try{
              e.printStackTrace(new PrintStream(baos));
              }finally{
              try {
baos.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
              }
              mylog.wmyLog(baos.toString());
             
              e.printStackTrace();
              session.getTransaction().rollback();
                 return false;
             }


文本中的错误信息: 


org.hibernate.exception.ConstraintViolationException: could not execute batch
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:129)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:132)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.doExecuteBatch(BatchingBatch.java:111)
at org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl.execute(AbstractBatchImpl.java:163)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.getBatch(JdbcCoordinatorImpl.java:206)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3102)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3587)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:103)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:453)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:345)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
at zyme.tools.hibernate.MyHibernateUtil.oneThreadCheckThanSaveAllUpgraded(MyHibernateUtil.java:244)
at threads.save.SaveThread.savebegin(SaveThread.java:37)
at threads.save.SaveThread.run(SaveThread.java:31)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.sql.BatchUpdateException: 批次处理 0 insert into cattagb_page (btname, burl, bvid, commentnums, curl, imgpath, jianjie, paiming, popularity, productnums, supercurlkey, turl, userdislike, usergrade, userlike, tburl) values ('...') 被中止,呼叫 getNextException 以取得原因。
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2762)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1891)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:405)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2909)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1135)
at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:123)
... 18 more


少了的部分:

[INFO ] [09:10:08] org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl - HHH000010: On release of batch it still contained JDBC statements
[WARN ] [09:10:08] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 23505
[ERROR] [09:10:08] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - 批次处理 0 insert into cattagb_page (btname, burl, bvid, commentnums, curl, imgpath, jianjie, paiming, popularity, productnums, supercurlkey, turl, userdislike, usergrade, userlike, tburl) values ('....') 被中止,呼叫 getNextException 以取得原因。
[WARN ] [09:10:08] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 23505
[ERROR] [09:10:08] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - 错误: 重复键违反唯一约束"uk_ex9kef7svstkgntmfy2vh5emn"
  详细:键值"(turl, burl)=(laVjN, ChsfT)" 已经存在
[ERROR] [09:10:08] org.hibernate.engine.jdbc.batch.internal.BatchingBatch - HHH000315: Exception executing batch [could not execute batch]


如何把控制台输出的完整错误信息保存到文本?

4 个解决方案

#1


log4j使用过吗?

完整保存所有日志到文件

#2


用过,log4j能实现不同类的日志保存到不同文件吗?  我需要额外记录几个重要的类的输出信息(错误和非错误信息都要,方便判断程序运行情况). 

#3


引用 2 楼 u013558606 的回复:
用过,log4j能实现不同类的日志保存到不同文件吗?  我需要额外记录几个重要的类的输出信息(错误和非错误信息都要,方便判断程序运行情况). 

可以的

#4


对的,楼上正解, log4j 功能强大,可以实现楼主的需求。
智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告