Class: TransmissionRSS::Log
- Includes:
- Singleton
- Defined in:
- lib/transmission-rss/log.rb
Overview
Encapsulates Logger as a singleton class.
Instance Method Summary collapse
-
#initialize(target = $stderr, level = :debug) ⇒ Log
constructor
A new instance of Log.
-
#level=(level) ⇒ Object
Change log level (String or Symbol).
-
#method_missing(sym, *args) ⇒ Object
If this class misses a method, call it on the encapsulated Logger class.
-
#target=(target) ⇒ Object
Change log target (IO, path to a file as String, or Symbol for IO constant).
Constructor Details
#initialize(target = $stderr, level = :debug) ⇒ Log
Returns a new instance of Log.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/transmission-rss/log.rb', line 9 def initialize(target = $stderr, level = :debug) @target = target @level = level @logger = Logger.new(target) @logger.level = to_level_const(level) @logger.formatter = proc do |sev, time, _, msg| time = time.strftime('%Y-%m-%d %H:%M:%S') "#{time} (#{sev.downcase}) #{msg}\n" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
If this class misses a method, call it on the encapsulated Logger class.
37 38 39 |
# File 'lib/transmission-rss/log.rb', line 37 def method_missing(sym, *args) @logger.send(sym, *args) end |
Instance Method Details
#level=(level) ⇒ Object
Change log level (String or Symbol)
32 33 34 |
# File 'lib/transmission-rss/log.rb', line 32 def level=(level) initialize(@target, level) end |