Class: Yell::Logger
- Inherits:
-
Object
- Object
- Yell::Logger
- Includes:
- Yell::Level::Helpers
- 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
-
#name ⇒ Object
The name of the logger instance.
Attributes included from Yell::Level::Helpers
Instance Method Summary collapse
-
#adapter(type = :file, *args, &block) ⇒ Yell::Adapter
Define an adapter to be used for logging.
-
#close ⇒ Object
Convenience method for resetting all adapters of the Logger.
-
#initialize(*args) {|_self| ... } ⇒ Logger
constructor
Initialize a new Logger.
-
#inspect ⇒ String
Get a pretty string representation of the logger.
Constructor Details
#initialize(*args) {|_self| ... } ⇒ Logger
Initialize a new Logger
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/yell/logger.rb', line 39 def initialize( *args ) @adapters = [] # extract options @options = args.last.is_a?(Hash) ? args.pop : {} # adapters may be passed in the options _extract_adapters!( @options ) # check if filename was given as argument and put it into the @options if [String, Pathname].include?(args.last.class) @options[:filename] = args.pop unless @options[:filename] end # set the log level when given self.level = @options[:level] # set the loggeer's name self.name = @options[:name] if @options[:name] # extract adapter self.adapter args.pop if args.any? # eval the given block yield(self) if block_given? # default adapter when none defined self.adapter :file if @adapters.empty? end |
Instance Attribute Details
#name ⇒ Object
The name of the logger instance
15 16 17 |
# File 'lib/yell/logger.rb', line 15 def name @name end |
Instance Method Details
#adapter(type = :file, *args, &block) ⇒ Yell::Adapter
Define an adapter to be used for logging.
91 92 93 94 95 96 97 |
# File 'lib/yell/logger.rb', line 91 def adapter( type = :file, *args, &block ) = [@options, *args].inject( Hash.new ) do |h, c| h.merge( [String, Pathname].include?(c.class) ? {:filename => c} : c ) end @adapters << Yell::Adapters.new( type, , &block ) end |
#close ⇒ Object
Convenience method for resetting all adapters of the Logger.
104 105 106 |
# File 'lib/yell/logger.rb', line 104 def close @adapters.each(&:close) end |
#inspect ⇒ String
Get a pretty string representation of the logger.
135 136 137 138 |
# File 'lib/yell/logger.rb', line 135 def inspect inspection = inspectables.inject( [] ) { |r, c| r << "#{c}: #{send(c).inspect}" } "#<#{self.class.name} #{inspection * ', '}, adapters: #{@adapters.map(&:inspect) * ', '}>" end |