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
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 68 69 70 71 72 |
# File 'lib/yell/logger.rb', line 41 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
17 18 19 |
# File 'lib/yell/logger.rb', line 17 def name @name end |
Instance Method Details
#add(options, *messages, &block) ⇒ Object
Somewhat backwards compatible method (not fully though)
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/yell/logger.rb', line 87 def add( , *, &block ) return false unless level.at?() = << block.call unless block.nil? = silencer.call(*) return false if .empty? event = Yell::Event.new(self, , *) write(event) end |
#close ⇒ Object
125 126 127 |
# File 'lib/yell/logger.rb', line 125 def close adapters.close end |
#inspect ⇒ Object
Get a pretty string representation of the logger.
119 120 121 122 |
# File 'lib/yell/logger.rb', line 119 def inspect inspection = inspectables.map { |m| "#{m}: #{send(m).inspect}" } "#<#{self.class.name} #{inspection * ', '}>" end |
#write(event) ⇒ Object
130 131 132 |
# File 'lib/yell/logger.rb', line 130 def write( event ) adapters.write(event) end |