Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

How can I silence Authority.logger in test environment? #101

Closed
natebird opened this issue Jun 16, 2015 · 6 comments
Closed

How can I silence Authority.logger in test environment? #101

natebird opened this issue Jun 16, 2015 · 6 comments
Assignees
Labels

Comments

@natebird
Copy link

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?

@nathanl
Copy link
Owner

nathanl commented Jun 17, 2015

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.

@nathanl
Copy link
Owner

nathanl commented Jun 17, 2015

I just pushed a commit to master to make this easier - want to try it out and let me know what you think?

@nathanl nathanl self-assigned this Jun 17, 2015
@natebird
Copy link
Author

Thank you for the quick response. I’ll try out master and see how it goes.

@nathanl
Copy link
Owner

nathanl commented Jul 18, 2015

Closing - let me know if you have further questions or issues.

@nathanl nathanl closed this as completed Jul 18, 2015
@nathanl
Copy link
Owner

nathanl commented Jul 20, 2015

See version 3.1.0

@natebird
Copy link
Author

That is just what I was looking for. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants