Reputation: 30211
In my java days I used to configure the logger so that different classes had different levels i.e.
Person.logger.level = :debug
Address.logger.level = :error
I haven't been able to find a way to do this with the ruby logger. Perhaps I need to create a separate logger for each class?
Upvotes: 2
Views: 517
Reputation: 8915
You may have luck with a lightweight approach known as log tagging. The inflexibility of standard logging packages has led me to develop and release Tagalog, which is a single-file, open-source logging system. There are versions of the library in PHP, Python, and Ruby available on github:
https://github.com/dorkitude/tagalog
or, specifically for the Ruby version:
https://github.com/dorkitude/tagalog.rb
A simple way to use it in your case is:
class Person
def self.log(input):
return Tagalog::log(input, [:person, :debug])
# ... (rest of class)
end
The advantages of tagging over levels are that you can turn tags on and off as you see fit, and they can be feature-specific, or they can just be levels like you're used to.
Upvotes: 2