Class: Yell::Logger
- Inherits:
-
Object
- Object
- Yell::Logger
- Defined in:
- lib/yell/logger.rb
Overview
The Yell::Logger
is your entrypoint. Anything onwards is derived from here.
A Yell::Logger
instance holds all your adapters and sends the log events to them if applicable. There are multiple ways of how to create a new logger.
Instance Attribute Summary collapse
-
#level(val = nil) ⇒ Object
Deprecated: Use attr_reader in future.
Instance Method Summary collapse
-
#adapter(type = :file, *args, &block) ⇒ Object
Define an adapter to be used for logging.
-
#close ⇒ Object
Convenience method for resetting all adapters of the Logger.
-
#initialize(*args, &block) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(*args, &block) ⇒ Logger
Returns a new instance of Logger.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/yell/logger.rb', line 36 def initialize( *args, &block ) @adapters = [] # extract options @options = args.last.is_a?(Hash) ? args.pop : {} # check if filename was given as argument and put it into the @options if args.last.is_a?( String ) @options[:filename] = args.pop unless @options[:filename] end # set the log level when given self.level = @options[:level] # extract adapter self.adapter args.pop if args.any? # eval the given block # block.call(self) if block _call( &block ) if block define! end |
Instance Attribute Details
#level(val = nil) ⇒ Object
Deprecated: Use attr_reader in future
34 35 36 |
# File 'lib/yell/logger.rb', line 34 def level @level end |
Instance Method Details
#adapter(type = :file, *args, &block) ⇒ Object
Define an adapter to be used for logging.
82 83 84 85 86 87 88 |
# File 'lib/yell/logger.rb', line 82 def adapter( type = :file, *args, &block ) = [@options, *args].inject( Hash.new ) do |h,c| h.merge( c.is_a?(String) ? {:filename => c} : c ) end @adapters << Yell::Adapters.new( type, , &block ) end |
#close ⇒ Object
Convenience method for resetting all adapters of the Logger.
118 119 120 |
# File 'lib/yell/logger.rb', line 118 def close @adapters.each(&:close) end |