从日志文件解析json对象 [英] parse json objects from a log file

查看:211
本文介绍了从日志文件解析json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的日志文件中解析JSON对象.为了使用JSON Parser,我的完整文件必须为JSON格式,而我却不是这种情况.有什么办法可以逐行解析文件并获取JSON对象. 下面是我的日志文件格式:

I want to parse the JSON objects from my log file. For using JSON Parser my complete files has to be in JSON format which is not the case with me. Is there any way I can parse the file line by line and get the JSON objects. Below is my log file format:

2015-10-19 11:24:35:701 INFO  BrokerTcpClient:28 - Set destination 
2015-10-19 11:24:35:929 DEBUG BrokerTcpClient:32 - received data: {type=data,  payload={

    "core" : [ {
      "id" : {
        "datatype" : "http://www.w3.org/2001/hk#long",
        "type" : "gh",
        "value" : "gh"
      },
      "entity" : {
        "type" : "uri",
        "value" : "http://fg.fg.com/ext/g/fg"
      },
      "Sno" : {
        "type" : "literal",
        "value" : "fg"
      }]
2015-10-19 11:24:35:701 INFO  BrokerTcpClient:28 - Set destination 
2015-10-19 11:24:35:929 DEBUG BrokerTcpClient:32
    "core" : [ {
      "id" : {
        "datatype" : "http://www.w3.org/2001/hk#long",
        "type" : "gh",
        "value" : "gh"
      },
      "entity" : {
        "type" : "uri",
        "value" : "http://fg.fg.com/ext/g/fg"
      },
      "Sno" : {
        "type" : "literal",
        "value" : "fg"
      }]

任何人都可以帮助我如何获取JSON对象.当我尝试解析一行JSON对象时,抛出异常.

Can any one please help how should I get my JSON objects. When I am trying to parse a single line of JSON objects throwing an exception.

推荐答案

您是否研究过logstash( https: //www.elastic.co/products/logstash )?它可以解决此问题,也可以解决尝试解析日志时可能遇到的其他问题.

Have you looked into logstash (https://www.elastic.co/products/logstash)? It can solve this problem and perhaps other problems you will come across when trying to parse logs.

这篇关于从日志文件解析json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆