【问题标题】:how to parse database error log?如何解析数据库错误日志?
【发布时间】:2011-09-21 02:37:48
【问题描述】:

我想解析一个数据库(MySQL、SQLite、Oracle,任何人都可以)错误日志以查看发生了哪些错误。是否有任何工具可用于完成这项工作,或者是否有人知道如何使用 PHP 或 Java 完成这项工作?请帮忙。

【问题讨论】:

    标签: java php parsing error-log


    【解决方案1】:

    假设您可以访问日志文件本身,知道您在日志文件中查找的CharSequence(“文本”),并希望使用 Java(例如 SE6)通过newBufferedReaderTutorial),然后用contains(CharSequence s)Tutorial mentioning thisAPI)查询日志文件的行,循环遍历。

    我头顶上未经测试的示例代码sn-ps:

        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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-19
      • 2020-08-29
      • 1970-01-01
      • 2010-09-14
      相关资源
      最近更新 更多