Class: ExtendedLogger::Factory
- Inherits:
-
Object
- Object
- ExtendedLogger::Factory
- Defined in:
- lib/extended_logger/factory.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #colors?(io) ⇒ Boolean
- #device ⇒ Object
-
#initialize(env) ⇒ Factory
constructor
A new instance of Factory.
- #level ⇒ Object
Constructor Details
#initialize(env) ⇒ Factory
Returns a new instance of Factory.
5 6 7 |
# File 'lib/extended_logger/factory.rb', line 5 def initialize env @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/extended_logger/factory.rb', line 3 def env @env end |
Class Method Details
.build(env = nil) ⇒ Object
9 10 11 12 |
# File 'lib/extended_logger/factory.rb', line 9 def self.build env=nil env ||= ENV new env end |
.call(*arguments) ⇒ Object
14 15 16 17 |
# File 'lib/extended_logger/factory.rb', line 14 def self.call *arguments instance = build *arguments instance.() end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/extended_logger/factory.rb', line 19 def call logger = ExtendedLogger.new device formatter = Formatter.new formatter.palette = Formatter.default_palette if colors? logger.io logger.formatter = formatter level = self.level logger.level = level if level logger end |
#colors?(io) ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/extended_logger/factory.rb', line 32 def colors? io if io.tty? ENV['LOG_COLOR'] != 'off' else ENV['LOG_COLOR'] == 'on' end end |
#device ⇒ Object
40 41 42 |
# File 'lib/extended_logger/factory.rb', line 40 def device ENV['LOG_DEVICE'] || $stdout end |
#level ⇒ Object
44 45 46 47 48 49 |
# File 'lib/extended_logger/factory.rb', line 44 def level if ENV.key? 'LOG_LEVEL' level , _ = ExtendedLogger.levels.rassoc ENV['LOG_LEVEL'].upcase level end end |