Created
October 10, 2013 10:10
-
-
Save kalpesh-fulpagare/6916038 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module KalpeshExtensions | |
def print *args | |
unless defined?(@log) | |
@log = Logger.new(Rails.root.to_s + "/log/custom.log") | |
@logger = Logger.new(Rails.root.to_s + "/log/#{Rails.env}.log") | |
end | |
puts "\n#{self.class.name}##{self.try(:action_name) rescue nil}\n#{'-' * 10} #{Time.now.strftime("%H:%M:%:S %P")} #{'-' * 10}" | |
@log.info "\n#{self.class.name}##{self.try(:action_name) rescue nil}\n#{'-' * 10} #{Time.now.strftime("%H:%M:%:S %P")} #{'-' * 10}" | |
@logger.info "\n#{self.class.name}##{self.try(:action_name) rescue nil}\n#{'-' * 10} #{Time.now.strftime("%H:%M:%:S %P")} #{'-' * 10}" | |
if args.present? | |
args.each do |arg| | |
if arg.class.name == 'Array' | |
arg.each {|a| print_it(a, true) } | |
else | |
print_it(arg) | |
end | |
end | |
end | |
puts "#{'-' * 10} #{Time.now.strftime("%H:%M:%S %P")} #{'-' * 10} \n" | |
@log.info "#{'-' * 10} #{Time.now.strftime("%H:%M:%S %P")} #{'-' * 10} \n\n" | |
@logger.info "#{'-' * 10} #{Time.now.strftime("%H:%M:%S %P")} #{'-' * 10} \n\n" | |
end | |
def print_it(arg, insp=false) | |
if insp | |
puts arg.inspect | |
@log.info arg.inspect | |
@logger.info arg.inspect | |
else | |
puts arg | |
@log.info arg | |
@logger.info arg | |
end | |
end | |
def clear | |
system 'clear' | |
end | |
end | |
include KalpeshExtensions | |
system `cat /dev/null > log/#{Rails.env}.log` | |
system `cat /dev/null > log/custom.log` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment