-1

I never wrote any complex regular expression before, and what I need seems to be (at least) a bit complicated.

I need a Regex to find matches for the following:

Here below show the logs for this i need regexp plesase help Thanking you in advance

Started GET \"/\" for 1x2.x6.1xx.2x at 2016-10-20 11:04:00 +0200
Processing by WelcomeController#index as HTML
Current user: anonymous
Redirected to http://example.pro.local/login?back_url=http%xx%xx%2Fexample.pro.local%2F
Filter chain halted as :check_if_login_required rendered or redirected
Completed 302 Found in 3.4ms (ActiveRecord: 1.9ms)"
Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88
pramod s
  • 31
  • 2
  • 7
  • 6
    what exactly is the pattern that you need to match? could you enhance your question with some example of what should and what should not be matched? – Chitharanjan Das Oct 20 '16 at 09:31
  • 1
    If this is not a one time thing, consider using the [logstasher gem](https://github.com/shadabahmed/logstasher) to generate your logs in json format. – ndnenkov Oct 20 '16 at 10:57
  • rubular.com can be helpful. – eeeeeean Oct 20 '16 at 19:35
  • I don't have specific code for you but Rails logger is configurable. I think it would make more sense to look into that than to make such a domain-specific regex. – max pleaner Oct 20 '16 at 22:07

1 Answers1

0

Extracting information from unstructured logs with regex is tedious and brittle. Instead it is preferable to make the application output logs in a structured format (as suggested by @ndn).

Consider using lograge and/or logstasher in your Rails application to output structured logs.

timstott
  • 344
  • 4
  • 11