加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
grok.py 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
toby2o12 提交于 2017-11-23 18:41 . add source
from pygrok import Grok
#text = 'gary is male, 25 years old and weighs 68.5 kilograms'
#text='INFO 2017-11-22 18:54:37,286 [116 ] loginfo - -QResumeCurstate-Count:select count(1) from scp_trustresume_curstate where creator_id=1033 and changed_status in (101,302,402,602,702,902) and role=3'
#text = 'INFO 2017-11-22 18:48:26,832 [100 ] zzz - 2017-11-22 18:48,收到请求:url:http://localhost:9100/resumefmanage/lockreleaselist/list,path:/resumefmanage/lockreleaselist/list,data:,body:{"role":2,"menutype":35,"jobId":-1,"SearchName":null,"SkipCount":20,"MaxResultCount":10},user_id:1033'
#pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms'
#text ='ERROR 2017-10-23 02:52:41,923 [136 ] ECommon.Remoting.SocketRemotingClient - Reconnect to server error'
text = 'INFO 2017-11-23 14:04:55,134 [78 ] loginfo - -QResumeCurstate-Count:select count(1) from scp_trustresume_curstate where creator_id=1033 and changed_status in (101,302,402,602,702,902) and role=3'
#pattern = '%{WORD:level} %{TIMESTAMP_ISO8601:date} \[%{NUMBER} \] %{DATA:LOGNAME}%{SPACE}-%{SPACE}%{GREEDYDATA}'
#pattern = '%{WORD:level} %{TIMESTAMP_ISO8601:date} \[%{NUMBER} \] (?<f>(request|zzz )) '
pattern = '%{WORD:level}%{SPACE}%{TIMESTAMP_ISO8601:date}%{SPACE}\[%{NUMBER}%{SPACE}\]%{SPACE}%{DATA:LOGNAME}%{SPACE}-%{SPACE}((%{GREEDYDATA},user_id:%{NUMBER:user_id})|%{GREEDYDATA})'
grok = Grok(pattern)
print(grok.match(text))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化