Class: Yell::Logger
- Inherits:
-
Object
- Object
- Yell::Logger
- Includes:
- Helpers::Adapter, Helpers::Base, Helpers::Formatter, Helpers::Level, Helpers::Silencer, Helpers::Tracer
- 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.
Instance Method Summary collapse
-
#add(options, *messages, &block) ⇒ Object
Somewhat backwards compatible method (not fully though).
- #close ⇒ Object
-
#initialize(*args, &block) ⇒ Logger
constructor
Initialize a new Logger.
-
#inspect ⇒ Object
Get a pretty string representation of the logger.
- #write(event) ⇒ Object
Methods included from Helpers::Silencer
Methods included from Helpers::Tracer
Methods included from Helpers::Adapter
Methods included from Helpers::Formatter
Methods included from Helpers::Level
Constructor Details
#initialize(*args, &block) ⇒ Logger
Initialize a new Logger
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/yell/logger.rb', line 44 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 |
Instance Attribute Details
#name ⇒ Object
The name of the logger instance
20 21 22 |
# File 'lib/yell/logger.rb', line 20 def name @name end |
Instance Method Details
#add(options, *messages, &block) ⇒ Object
Somewhat backwards compatible method (not fully though)
90 91 92 93 94 95 96 97 98 |
# File 'lib/yell/logger.rb', line 90 def add( , *, &block ) return false unless level.at?() = silencer.call(*) return false if .empty? event = Yell::Event.new(self, , *, &block) write(event) end |
#close ⇒ Object
126 127 128 |
# File 'lib/yell/logger.rb', line 126 def close adapters.close end |
#inspect ⇒ Object
Get a pretty string representation of the logger.
120 121 122 123 |
# File 'lib/yell/logger.rb', line 120 def inspect inspection = inspectables.map { |m| "#{m}: #{send(m).inspect}" } "#<#{self.class.name} #{inspection * ', '}>" end |
#write(event) ⇒ Object
131 132 133 |
# File 'lib/yell/logger.rb', line 131 def write( event ) adapters.write(event) end |