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
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

Returns:

  • (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

#deviceObject



39
40
41
# File 'lib/extended_logger/factory.rb', line 39

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