我有一份字典清单。你知道吗
data = [
{'@timestamp': '2018-10-29T05:57:12.722Z','messages': '[FANATIC] - - Session id kajdhrg7uhdfvbshfgadf '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': '[FANATIC] - - Exception Lorem Ipsum Rebolt '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'JHUSHDVCHBASJd'},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'asdfawerg cdv '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'fya7 5 Lorem Ipsum Rebolt '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'zxcgwrt asdfg w4e6354gdf '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'zcfb26 eqrgsfdb syh2456ytdfg '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'we57hb354gf '},
{'@timestamp': '2018-10-29T06:59:12.722Z','messages': '[FANATIC] - - sdfsum Rebolt '},
{'@timestamp': '2018-10-29T06:59:12.722Z','messages': '[FANATIC] - - sdfsum Rebolt '}
]
这是一个日志模式。但是错误日志新行没有[FANATIC]
,它应该在单行或单个消息中。你知道吗
有没有办法让那些在新的字典里只包含错误的共轭信息?你知道吗
for i in data:
if "[FANATIC]" in i['messages'] and "exception" in i['messages']:
print(i)
我能在新字典里找到“行间”吗?你知道吗
编辑:
我想要的类似于下面的…:
data = [
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': '[FANATIC] - - Exception Lorem Ipsum Rebolt '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'JHUSHDVCHBASJd'},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'asdfawerg cdv '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'fya7 5 Lorem Ipsum Rebolt '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'zxcgwrt asdfg w4e6354gdf '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'zcfb26 eqrgsfdb syh2456ytdfg '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': 'we57hb354gf '},
{'@timestamp': '2018-10-29T06:58:12.722Z', 'messages': [
'[FANATIC] - - Exception Lorem Ipsum Rebolt',
'JHUSHDVCHBASJd',
'asdfawerg cdv ',
'fya7 5 Lorem Ipsum Rebolt ',
'zxcgwrt asdfg w4e6354gdf ',
'we57hb354gf '
]
},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': '[FANATIC] - - sdfsum Rebolt '},
{'@timestamp': '2018-10-29T06:58:12.722Z','messages': '[FANATIC] - - sdfsum Rebolt '}
]
只需用理解力过滤你的列表:
或者对于这两种检查:
为了得到“线之间”的东西,你可以从左到右剥离:
但对于更复杂的东西,
regex
会更好。你知道吗这里有一个live example
我将异常添加到一个中间列表中,然后将该列表存储在另一个列表中
输出
相关问题 更多 >
编程相关推荐