Module: Suture::Wrap::Logger

Defined in:
lib/suture/wrap/logger.rb

Defined Under Namespace

Classes: NullIO

Class Method Summary collapse

Class Method Details

.init(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/suture/wrap/logger.rb', line 5

def self.init(options)
  @logger = if options[:log_file]
    full_path = File.join(Dir.getwd, options[:log_file])
    FileUtils.mkdir_p(File.dirname(full_path))
    ::Logger.new(full_path)
  else
    ::Logger.new(NullIO.new)
  end

  @logger.level = if options[:log_level]
                    ::Logger.const_get(options[:log_level])
                  else
                    ::Logger::INFO
                  end

  @logger.formatter = proc { |_, time , _, msg|
    formatted_time = time.strftime("%Y-%m-%dT%H:%M:%S.%6N")
    "[#{formatted_time}] Suture: #{msg}\n".tap { |out|
      puts out if options[:log_stdout]
      options[:log_io].write(out) if options[:log_io]
    }
  }

  return @logger
end