Suggestion: don't assume Rails logger is present; make logger configurable #38

nathanl opened this Issue Jan 21, 2014 · 3 comments


None yet

2 participants


I'm joining a non-Rails project that uses this gem. I just ran the tests and got a backtrace that included this:

...../gems/flag_shih_tzu-0.3.2/lib/flag_shih_tzu.rb:209:in `check_flag_column': 
private method `warn' called for nil:NilClass (NoMethodError)

That goes to a line like this (on master):

Turns out that you're trying to give me a helpful error, but I actually got a very confusing one. 😆

This line assumes that the Rails logger is present (right?).

An approach I've seen that gets around that is to have a configurable logger. Eg, when you want to log, call FlagShihTzu.logger.warn('whatever'). That would be a method like:

module FlagShihTzu
  def self.logger
    @logger ||= configuration.logger

Then users could configure your log messages to point wherever they want in a configuration file. Eg, configuration.logger = Rails.logger in a Rails app, or configuration.logger =, where my_location could be 'some_file.log' or STDOUT or '/dev/null'.

This is a trick @adamhunter showed me, which we used in Authority:

Just an idea.


I do exactly that on many of my gems. I just haven't had time to implement it on this one! It's on my mental list of things to get done. Thanks for documenting it as an issue!


I have removed the logger altogether. Now just using Kernel#warn across the board.


I think for now that is sufficient, but pull request would be welcome with a real customizable logger implementation.

@pboling pboling closed this Jul 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment