Finally did this by using emaillenin's answer thanx emaillenin :D.
Here is solution
# Overriding Rails logger to not save IP addresses for specific paths
# Put this file in <app_root>/config/initializers
# defining setter for Rails default log formatter, so later we can set our custom logger using '='
class ActiveSupport::BufferedLogger
def formatter=(formatter)
@log.formatter = formatter
end
end
# Modified Formatter Class with custom 'call' method
class Formatter
Format = "%s\n"
# Remove IP while getting request on below specified Path
FilteredActionRegexp = /app_path|another_path/i
# reference for regexp of IP address
# http://answers.oreilly.com/topic/318-how-to-match-ipv4-addresses-with-regular-expressions/
IPRegexp = /\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/
FilteredString = '**FILTERED**'
def call(severity, time, progname, msg)
Format % [msg2str(filter_ip(msg))]
end
private
def msg2str(msg)
case msg
when ::String
msg
when ::Exception
"#{ msg.message } (#{ msg.class })\n" <<
(msg.backtrace || []).join("\n")
else
msg.inspect
end
end
# Replace IP Address with custom string if action is filtered
def filter_ip(msg)
# Replace only if message contains filtered action
if msg =~ FilteredActionRegexp
# If log string contains IP address then remove it with custom string
msg.gsub(IPRegexp, FilteredString )
else
msg
end
end
end
# Override Rails default logger formatter
Rails.logger.formatter = Formatter.new