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.
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 |
# File 'lib/extended_logger/factory.rb', line 19 def call logger = ExtendedLogger.new device if colors? logger.io logger.formatter = ColoredFormatter.new else logger.formatter = Formatter.new end logger end |
#colors?(io) ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/extended_logger/factory.rb', line 31 def colors? io if io.tty? ENV['LOGGER_COLORS'] != 'off' else ENV['LOGGER_COLORS'] == 'on' end end |
#device ⇒ Object
39 40 41 |
# File 'lib/extended_logger/factory.rb', line 39 def device ENV['LOGGER_DEVICE'] || $stdout end |