如何防止 Android SQLite 将堆栈跟踪转储到 logcat?
在 Android 2.3.3 上,我正在使用 API 方法批量导入到我的 SQLite 表之一:
SQLiteDatabase.insert(String table, String nullColumnHack, ContentValues value)
它工作正常,但如果有任何数据库错误行(例如约束错误)将完整的堆栈跟踪写入 Android Logcat,它很快就会填满。
我怎样才能关闭这个堆栈跟踪?
我已经处理了抛出的任何异常,但 Logcat 正在从 SQLite 库代码中受到污染。
我担心移动设备上的性能。
- 启用导入事务已经
- 预加载数据库是不可能的,因为数据可能会改变
应该强制执行约束,我将处理违规,但 Logcat 中每个违规的 20 行堆栈跟踪乘以数百个违规是我想要关闭的。
不幸的是,我也无法使用 Android Froyo 引入的高级冲突处理,因为应用程序也必须在旧设备上运行。
干杯。
On Android 2.3.3 I'm doing a bulk import into one of my SQLite tables, using the API method:
SQLiteDatabase.insert(String table, String nullColumnHack, ContentValues values)
It works fine, but if there is a database error with any row (e.g. constraint error) a full stack trace is written to Android Logcat which quickly fills up.
How can I turn off this stack trace?
I already handle any Exception being thrown but the Logcat is being polluted from within the SQLite library code.
I am worried about performance on mobile devices.
- transactions for import are enabled already
- preloaded DB is impossible because data might change
Constraints should be enforced and I will handle violation, but 20 line stack traces in Logcat for each violation multiplied by hundreds of violations is what I want to turn off.
Unfortunately I also cannot use advanced conflict handling introduced with Android Froyo because app must also run on older devices.
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,我刚刚找到了如下解决方案:
我必须使用不同的 API 方法(不是
SQLiteDatabase.insert()
):现在,异常从 SQLite 库中抛出,正如预期的那样,并且没有堆栈跟踪被转储。
OK, I just found the solution as follows:
I have to use a different API method (not
SQLiteDatabase.insert()
):Now, the exception is thrown from the SQLite library, as expected and no stack trace is dumped.
只需根据标签或进程 ID 过滤掉您不感兴趣的任何内容即可。您可以在 Eclipse 中的 Logcat 查看器中轻松完成此操作,或者如果您在命令行上使用 Logcat 说明在这里。
Just filter out any stuff you're not interested in, based on the tag or the process ID. You can do it easily in the Logcat viewer in Eclipse, or if you're using Logcat on the command line the instructions are here.
这不是污染。 LogCat 的目的是注册设备/模拟器上发生的所有事情。
如果您想过滤掉 LogCat,则可以在 Eclipse 中实现(您可以按日志标记、按 pid 或按日志级别进行过滤),从而提供一种从 LogCat 窗口“删除”不需要的异常的方法。
编辑如果问题是性能(根据您的评论),我认为您不必担心。
It's not pollution. It's the purpose of LogCat to register everything that's going on on the device / emulator.
If you want to filter out your LogCat, it's possible in Eclipse (you can filter by log tag, by pid, or by log level), thus providing a way to "remove" unwanted exceptions from a LogCat window.
EDIT If the issue is performance (according to your comments), I don't think you should worry.