Cleanest way to make logging in Ruby Gem "library" be visible in Rails.logger? -
i know how log in rails through using rails.logger. question is, how make methods of object has been externalized gem required ruby on rails application log appropriately, can seen in standard rails log when needs output something? there way can without requiring rails in gemfile?
for example, since object code used part of rails application, see following:
if (val1 == val2) ## converted strings same, log differences (something misparsed) ## example, there can mis-parsings between unit number , post-directionals logger.warn "curious address mismatch (1) :: #{first}" ##todo: set these logging statements log errors correctly when method called in delayed job (which case in mintrak2) logger.warn "curious address mismatch (2) :: #{second}" return true end this logger used part of rails application, , conceivably rails.logger. no longer applies, , when gem need debug, see error:
d, [2016-11-10t11:57:03.581467 #12602] debug -- : error importing fileset: undefined local variable or method `logger' addressparser:class d, [2016-11-10t11:57:03.581660 #12602] debug -- : bt: /var/www/mintrak2/shared/bundle/ruby/2.1.0/bundler/gems/ehs-address-parser-lib-f390aacab26a/lib/tlc_address_parser.rb:649:in `compare_address_hashes' should require rails , move on? there cli frontend library i'm using can work without rails, don't want bog down library rails dependencies.
thanks!
you can either make sure rails loaded, qualify path logger, (i.e. rails.logger.warn), or make singleton has property can set inside rails application. use initializer dependency inject reference rails logger.
Comments
Post a Comment