Skip to content

Instantly share code, notes, and snippets.

@noahsw
Forked from dougc84/awesome_print.rb
Last active December 23, 2015 21:19
Show Gist options
  • Select an option

  • Save noahsw/6695178 to your computer and use it in GitHub Desktop.

Select an option

Save noahsw/6695178 to your computer and use it in GitHub Desktop.
This is a revised gist that allows you to safely leave your awesome_print and awesome_inspect calls in production.
# The following snippet handles any calls to ap or awesome_print hanging out in your code,
# which can be particularly troublesome in a production environment where awesome_print isn't
# included in your Gemfile.
# If you have any inline "ap" or "awesome_print" calls, they will be aliased to
# puts (not using the alias method, that wasn't optimal). The output will also be logged at
# info level (feel free to change this depending on your needs) with the calling file and
# line number so you can find the offending calls.
# You can grep through your log files for "[ AP called from " to find any calls to ap.
# Throw this code in an initializer (awesome_print.rb) and modify as you wish.
# I updated the original gist and included awesome_inspect support
if Rails.env.production?
module Kernel
def ap(object, options = {})
puts object
Rails.logger.debug "[ AP called from #{caller(0).last} ]: #{object}"
end
def ai(options = {})
puts self
Rails.logger.debug "[ AP called from #{caller(0).last} ]: #{self}"
end
end
# i'm not sure if this line is absolutely necessary, but it works.
alias :awesome_print :ap
alias :awesome_inspect :ai
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment