Class: ExtendedLogger::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/extended_logger/factory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#envObject (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

#callObject



19
20
21
22
23
24
25
26
27
# 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

  logger
end

#colors?(io) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/extended_logger/factory.rb', line 29

def colors? io
  if io.tty?
    ENV['LOGGER_COLOR'] != 'off'
  else
    ENV['LOGGER_COLOR'] == 'on'
  end
end

#deviceObject



37
38
39
# File 'lib/extended_logger/factory.rb', line 37

def device
  ENV['LOGGER_DEVICE'] || $stdout
end