正则表达式来解析Ruby的日志消息

2015-09-08 0 641
正则表达式来解析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 正则表达式来解析Ruby的日志消息 http://www.ox520.com/16478.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务