解析Ruby日志消息的正则表达式
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解析Ruby日志消息的正则表达式相关的知识,希望对你有一定的参考价值。
# parse ruby log message # customize as needed LOG_EXPRESSION = /([w]+),s+[([^]s]+)s+#([^]]+)]s+(w+)s+--s+(w+)?:s+(.+)/ # sample log output from this call: # logger.info("Ubiquitously") { "[dequeud] #{JSON.generate(params)}"} string = 'I, [2010-08-15T16:16:46.142801 #81977] INFO -- Ubiquitously: {"title":"Google","url":"google.com","tags":"search, google, api","services":["meta_filter","mixx"],"description":"a search engine!"}' sample_output.gsub(LOG_EXPRESSION) do |match| severity = $1 date = $2 # Time.parse(date) pid = $3 label = $4 app = $5 message = $6 end
以上是关于解析Ruby日志消息的正则表达式的主要内容,如果未能解决你的问题,请参考以下文章