Closed natebird closed 9 years ago
Hi, Nate!
Authority expects to have its logger set to an object that is or acts like an instance of Logger - specifically, that responds to .warn
(currently, that's the only method Authority calls on it).
So you could make your own dummy object, if you like:
o = Object.new
def o.warn(*args)
# do nothing
end
...but a more typical way to do it would be (at least on a Linix or Mac system) would be to use Logger.new('/dev/null')
.
If you ran the Rails generator, you can look in config/initializers/authority.rb
for more info. That initializer would be the most straightforward place to change it, using a conditional like config.logger = Rails.env.test? ? Logger.new('/dev/null') : Logger.new(STDOUT)
.
What you tried to do looks sensible, but doesn't work because Authority
doesn't have a logger=
method, so you can't set it directly. You should be able to do
config = Authority.configuration
config.logger = my_logger
Authority.configuration = config
but that doesn't have any effect, because after the first call, the Authority
module hangs on to the first logger it saw instead of consulting the current configuration object. I can't see any reason for that, so I'll change it.
I just pushed a commit to master to make this easier - want to try it out and let me know what you think?
Thank you for the quick response. I’ll try out master and see how it goes.
Closing - let me know if you have further questions or issues.
See version 3.1.0
That is just what I was looking for. Thanks!
Can I add something to my spec_helper.rb file to silence the Authority logging output?
I tried
Authority.logger = nil
but that isn’t possible. Any other ideas?