Object
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.
Initialize a new Logger
@example A standard file logger
Yell::Logger.new 'development.log'
@example A standard datefile logger
Yell::Logger.new :datefile Yell::Logger.new :datefile, 'development.log'
@example Setting the log level
Yell::Logger.new :level => :warn Yell::Logger.new do |l| l.level = :warn end
@example Combined settings
Yell::Logger.new 'development.log', :level => :warn Yell::Logger.new :datefile, 'development.log' do |l| l.level = :info end
# File lib/yell/logger.rb, line 43 def initialize( *args, &block ) # extract options @options = args.last.is_a?(Hash) ? args.pop : {} # 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 reset! # FIXME: :format is deprecated in future versions --R self.formatter = Yell.__fetch__(@options, :format, :formatter) self.level = Yell.__fetch__(@options, :level, :default => 0) self.name = Yell.__fetch__(@options, :name) self.trace = Yell.__fetch__(@options, :trace, :default => :error) # silencer self.silence(*Yell.__fetch__(@options, :silence, :default => [])) # adapters may be passed in the options extract!(*Yell.__fetch__(@options, :adapters, :default => [])) # extract adapter self.adapter(args.pop) if args.any? # eval the given block block.arity > 0 ? block.call(self) : instance_eval(&block) if block_given? # default adapter when none defined self.adapter(:file) if adapters.empty? end
Somewhat backwards compatible method (not fully though)
# File lib/yell/logger.rb, line 89 def add( options, *messages, &block ) return false unless level.at?(options) messages = silencer.call(*messages) return false if messages.empty? event = Yell::Event.new(self, options, *messages, &block) write(event) end
@private
# File lib/yell/logger.rb, line 125 def close adapters.close end
Get a pretty string representation of the logger.
# File lib/yell/logger.rb, line 119 def inspect inspection = inspectables.map { |m| "#{m}: #{send(m).inspect}" } "#<#{self.class.name} #{inspection * ', '}>" end
Set the name of a logger. When providing a name, the logger will automatically be added to the Yell::Repository.
@return [String] The logger’s name
# File lib/yell/logger.rb, line 81 def name=( val ) Yell::Repository[val] = self if val @name = val.nil? ? "<#{self.class.name}##{object_id}>": val @name end
Generated with the Darkfish Rdoc Generator 2.