Regular Expression to Parse Ruby Log Messages


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # parse ruby log message
  2. # customize as needed
  3. LOG_EXPRESSION = /([\w]+),\s+\[([^\]\s]+)\s+#([^\]]+)]\s+(\w+)\s+--\s+(\w+)?:\s+(.+)/
  4.  
  5. # sample log output from this call:
  6. # logger.info("Ubiquitously") { "[dequeud] #{JSON.generate(params)}"}
  7. 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!"}'
  8.  
  9. sample_output.gsub(LOG_EXPRESSION) do |match|
  10. severity = $1
  11. date = $2 # Time.parse(date)
  12. pid = $3
  13. label = $4
  14. app = $5
  15. message = $6
  16. end

URL: regular-expression-to-parse-ruby-log-messages

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.