Skip to content

Instantly share code, notes, and snippets.

@marocchino
Created July 10, 2012 05:48
Show Gist options
  • Save marocchino/3081402 to your computer and use it in GitHub Desktop.
Save marocchino/3081402 to your computer and use it in GitHub Desktop.
syslog rails2 log parse regex
# ref
# https://github.com/wvanbergen/request-log-analyzer/blob/master/lib/request_log_analyzer/file_format.rb
patterns = {
:completed => '(Completed in (?<duration>\d+)ms \((?:View: (?<view>\d+))?,?(?:.?DB: (?<db>\d+))?\)? \| (?<status>\d{3}).+\[(?<url>http.+)\])',
:processing => '(Processing (?<controller>(?:\w+::)*\w+)#(?<action>\w+)(?: to (?<format>\w+))? \(for (?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) at (?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\) \[(?<method>[A-Z]+)\])',
:failure => '((?<error>(?:[A-Z]\w*[a-z]\w+\:\:)*[A-Z]\w*[a-z]\w+) \((?<message>.*)\)(?: on line #(?<line>\d+) of (?<file>.+))?\:\s*$)',
:cache_hit => '(Filter chain halted as \[\#<ActionController::Filters::AroundFilter.*\@method=.*(?:Caching::Actions::ActionCacheFilter|action_controller\/caching\/actions\.rb).*\] did_not_yield)',
:parameters => '(Parameters:\s+(?<parameter>\{.*\}))',
:default => '(?<message>.*)',
}
syslog_rails2 = /^(?<time>[^ ]*\s*[^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?[^\:]*\: *(#{patterns.values.join("|")})$/
p syslog_rails2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment