我想解析数据库(MySQL,SQLite,Oracle,任何人都可以)错误日志以查看发生了哪些错误。有没有工具可以完成这项工作,或者有人知道如何使用PHP或Java完成工作吗?请帮忙。
答案 0 :(得分:0)
假设您有权访问日志文件本身,请在日志文件中知道您要查找的CharSequence
(“文本”),并希望用Java(例如,SE6)读取文件通过newBufferedReader
(Tutorial),然后使用contains(CharSequence s)
(Tutorial mentioning this,API)查询日志文件的行,循环显示这些行。< / p>
未经测试的示例代码摘自我的头脑:
File file = full-path-to-your-file // Replace with file path
Charset charset = Charset.forName("your-charset"); // Replace with file's charset
try (BufferedReader reader = Files.newBufferedReader(file, charset)) {
String line = null;
while ((line = reader.readLine()) != null) {
if (line.contains(error-char-sequence)) // Replace with CharSequence you're looking for
System.out.println("Log file contains error message!");
}
} catch (IOException x) {
System.err.format("IOException: %s%n", x);
}