Class: Logger::Logging::Factory
- Inherits:
-
Object
- Object
- Logger::Logging::Factory
- Defined in:
- lib/logger/logging/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
- #coloring? ⇒ Boolean
- #device ⇒ Object
-
#initialize(env) ⇒ Factory
constructor
A new instance of Factory.
- #level ⇒ Object
- #logger_class ⇒ Object
Constructor Details
#initialize(env) ⇒ Factory
Returns a new instance of Factory.
5 6 7 |
# File 'lib/logger/logging/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/logger/logging/factory.rb', line 3 def env @env end |
Class Method Details
.call(env = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/logger/logging/factory.rb', line 9 def self.call env = nil env ||= ENV instance = new env instance.() end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 |
# File 'lib/logger/logging/factory.rb', line 15 def call logger = logger_class.new device logger.level = level logger end |
#coloring? ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/logger/logging/factory.rb', line 50 def coloring? return @coloring unless @coloring.nil? @coloring = begin use_colors = env.fetch "LOG_COLOR" do if device.tty? then "on" else "off" end end use_colors == "on" end end |
#device ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/logger/logging/factory.rb', line 21 def device @device ||= begin path = env.fetch "LOG_DEVICE" do "/dev/stdout" end if path.is_a? String then File.open path, "a" else path end end end |
#level ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/logger/logging/factory.rb', line 29 def level @level ||= begin level_name = env.fetch "LOG_LEVEL" do "WARN" end level_name = level_name.upcase if Logger.const_defined? level_name Logger.const_get level_name else { "DATA" => -2, "TRACE" => -1, }.fetch level_name end end end |
#logger_class ⇒ Object
46 47 48 |
# File 'lib/logger/logging/factory.rb', line 46 def logger_class if coloring? then ColoredLogger else ExtendedLogger end end |