java正则表达式解析Mysql数据库错误日志

ChenS27 2018-03-21 09:51:08
以下为Mysql数据库错误日志中的一条语句:
2018-03-21T13:46:01.185376Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

求哪位大神用JAVA正则表达式解析一下!十分感谢!!!
...全文
665 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChenS27 2018-07-18
  • 打赏
  • 举报
回复
已经解决了,感谢各位。
weixin_39670158 2018-03-26
  • 打赏
  • 举报
回复
隐式DEFAULT值废弃了 换个关键字试试
  • 打赏
  • 举报
回复
    public static void main(String[] args) {
        System.out.println( new ReadSingleLineNumber().test2());
    }

    MySqlLog test2(){
        String log = "2018-03-21T13:46:01.185376Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).";
        String[] head = log.substring(0, log.indexOf(']') + 1).split(" ");
        return new MySqlLog(head[0].trim(), Integer.parseInt(head[1].trim()), head[2].trim().substring(head[2].trim().indexOf('[') + 1, head[2].trim().indexOf(']')), log.substring(log.indexOf(']') + 2).trim());
    }

    class MySqlLog{
        String time;
        int index;
        String level;
        String msg;
        public MySqlLog(String time, int index, String level, String msg) {
            this.time = time;
            this.index = index;
            this.level = level;
            this.msg = msg;
        }

        @Override
        public String toString() {
            return "MySqlLog{" +
                    "time='" + time + '\'' +
                    ", index=" + index +
                    ", level='" + level + '\'' +
                    ", msg='" + msg + '\'' +
                    '}';
        }
    }
运行结果: MySqlLog{time='2018-03-21T13:46:01.185376Z', index=0, level='Warning', msg='TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).'}
  • 打赏
  • 举报
回复
攻占2楼: 这么有规律的东西好像用不上正则吧,你看,第一个空格之前代表日期,第二个好像是消息的序号吧 直接从第0个开始,截到第3个空格的位置,然后 拆分空格就能得到 日期 索引号 警告级别 在从第三个空格开始 到结束都是错误消息
  • 打赏
  • 举报
回复

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧