lib/ernie.rb in ernie-2.5.1 vs lib/ernie.rb in ernie-2.5.2

- old
+ new

@@ -1,11 +1,11 @@ require 'rubygems' require 'bert' require 'logger' class Ernie - VERSION = '2.5.1' + VERSION = '2.5.2' class << self attr_accessor :mods, :current_mod, :log attr_accessor :auto_start attr_accessor :count, :virgin_procline @@ -121,12 +121,12 @@ # Start the processing loop. # # Loops forever def self.start self.procline('starting') - self.log.info("(#{Process.pid}) Starting") - self.log.debug(self.mods.inspect) + self.log.info("(#{Process.pid}) Starting") if self.log.level <= Logger::INFO + self.log.debug(self.mods.inspect) if self.log.level <= Logger::DEBUG input = IO.new(3) output = IO.new(4) input.sync = true output.sync = true @@ -136,48 +136,50 @@ iruby = self.read_berp(input) self.count += 1 unless iruby puts "Could not read BERP length header. Ernie server may have gone away. Exiting now." - self.log.info("(#{Process.pid}) Could not read BERP length header. Ernie server may have gone away. Exiting now.") + if self.log.level <= Logger::INFO + self.log.info("(#{Process.pid}) Could not read BERP length header. Ernie server may have gone away. Exiting now.") + end exit! end if iruby.size == 4 && iruby[0] == :call mod, fun, args = iruby[1..3] self.procline("#{mod}:#{fun}(#{args})") - self.log.info("-> " + iruby.inspect) + self.log.info("-> " + iruby.inspect) if self.log.level <= Logger::INFO begin res = self.dispatch(mod, fun, args) oruby = t[:reply, res] - self.log.debug("<- " + oruby.inspect) + self.log.debug("<- " + oruby.inspect) if self.log.level <= Logger::DEBUG write_berp(output, oruby) rescue ServerError => e oruby = t[:error, t[:server, 0, e.class.to_s, e.message, e.backtrace]] - self.log.error("<- " + oruby.inspect) - self.log.error(e.backtrace.join("\n")) + self.log.error("<- " + oruby.inspect) if self.log.level <= Logger::ERROR + self.log.error(e.backtrace.join("\n")) if self.log.level <= Logger::ERROR write_berp(output, oruby) rescue Object => e oruby = t[:error, t[:user, 0, e.class.to_s, e.message, e.backtrace]] - self.log.error("<- " + oruby.inspect) - self.log.error(e.backtrace.join("\n")) + self.log.error("<- " + oruby.inspect) if self.log.level <= Logger::ERROR + self.log.error(e.backtrace.join("\n")) if self.log.level <= Logger::ERROR write_berp(output, oruby) end elsif iruby.size == 4 && iruby[0] == :cast mod, fun, args = iruby[1..3] self.procline("#{mod}:#{fun}(#{args})") - self.log.info("-> " + [:cast, mod, fun, args].inspect) + self.log.info("-> " + [:cast, mod, fun, args].inspect) if self.log.level <= Logger::INFO begin self.dispatch(mod, fun, args) rescue Object => e # ignore end write_berp(output, t[:noreply]) else self.procline("invalid request") - self.log.error("-> " + iruby.inspect) + self.log.error("-> " + iruby.inspect) if self.log.level <= Logger::ERROR oruby = t[:error, t[:server, 0, "Invalid request: #{iruby.inspect}"]] - self.log.error("<- " + oruby.inspect) + self.log.error("<- " + oruby.inspect) if self.log.level <= Logger::ERROR write_berp(output, oruby) end end end