Class: Logification::Logger
- Inherits:
-
Object
- Object
- Logification::Logger
- Includes:
- Helpers::LoggingMethods, Helpers::Wrapper
- Defined in:
- lib/logification/logger.rb
Constant Summary
Constants included from Helpers::LoggingMethods
Instance Attribute Summary collapse
-
#base_logger ⇒ Object
Returns the value of attribute base_logger.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nested_count ⇒ Object
Returns the value of attribute nested_count.
Instance Method Summary collapse
- #default_logger(name) ⇒ Object
- #duplicate(name, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Logger
constructor
A new instance of Logger.
- #level ⇒ Object
- #level=(value) ⇒ Object
- #method_missing(meth, *args, &block) ⇒ Object
Methods included from Helpers::Wrapper
Methods included from Helpers::LoggingMethods
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(options = {}) ⇒ Logger
Returns a new instance of Logger.
12 13 14 15 16 17 |
# File 'lib/logification/logger.rb', line 12 def initialize(={}) self.name = [:name] || "logification" self.base_logger = [:base_logger] || default_logger(@name) self.nested_count = [:nested_count] || 0 self.level = [:level] || :debug end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/logification/logger.rb', line 44 def method_missing(meth, *args, &block) begin if block_given? if args.empty? base_logger.send(meth) { block } else base_logger.send(meth, *args, &block) end else if args.empty? base_logger.send(meth) else base_logger.send(meth, *args) end end rescue NoMethodError => ex super end end |
Instance Attribute Details
#base_logger ⇒ Object
Returns the value of attribute base_logger.
7 8 9 |
# File 'lib/logification/logger.rb', line 7 def base_logger @base_logger end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/logification/logger.rb', line 7 def name @name end |
#nested_count ⇒ Object
Returns the value of attribute nested_count.
7 8 9 |
# File 'lib/logification/logger.rb', line 7 def nested_count @nested_count end |
Instance Method Details
#default_logger(name) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/logification/logger.rb', line 19 def default_logger(name) ::Logger.new(STDOUT).tap do |l| l.level = translate_level_in(:debug) l.formatter = Logification::Formatters::Colorized.new l.progname = self.name end end |
#duplicate(name, options = {}) ⇒ Object
39 40 41 42 |
# File 'lib/logification/logger.rb', line 39 def duplicate(name, ={}) settings = current_settings.merge() self.class.new(settings.merge(name: name)) end |
#level ⇒ Object
31 32 33 |
# File 'lib/logification/logger.rb', line 31 def level translate_level_out(base_logger.level) end |
#level=(value) ⇒ Object
35 36 37 |
# File 'lib/logification/logger.rb', line 35 def level=(value) base_logger.level = translate_level_in(value) end |