Class: RDKit::Logger

Inherits:
Object show all
Defined in:
lib/rdkit/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(log_path = nil) ⇒ Logger

Returns a new instance of Logger.



3
4
5
# File 'lib/rdkit/logger.rb', line 3

def initialize(log_path=nil)
  @io = log_path ? File.open(log_path, 'a') : $stdout
end

Instance Method Details

#debug(message) ⇒ Object



7
8
9
10
11
# File 'lib/rdkit/logger.rb', line 7

def debug(message)
  return unless $DEBUG && ENV['RACK_ENV'] != 'test'

  log(message)
end

#info(message) ⇒ Object



13
14
15
# File 'lib/rdkit/logger.rb', line 13

def info(message)
  log(message)
end

#log(message) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/rdkit/logger.rb', line 21

def log(message)
  case message
  when Exception
    @io.puts message.inspect
    @io.puts message.backtrace.join("\n")
  else
    @io.puts message
  end
  @io.flush
end

#warn(message) ⇒ Object



17
18
19
# File 'lib/rdkit/logger.rb', line 17

def warn(message)
  log(message)
end