lib/i2x/agent.rb in i2x-0.0.6 vs lib/i2x/agent.rb in i2x-0.0.7
- old
+ new
@@ -10,12 +10,13 @@
@publisher = agent[:publisher]
@payload = agent[:payload]
@cache = agent[:payload][:cache]
@seeds = agent[:seeds]
@selectors = agent[:payload][:selectors]
+ I2X::Config.log.debug(self.class.name) {"Agent #{@identifier} initialized"}
rescue Exception => e
- p "[i2x] unable to initialize agent. #{e}"
+ I2X::Config.log.error(self.class.name) {"Unable to initialize agent. #{e}"}
end
end
@@ -29,32 +30,32 @@
when 'sql'
begin
@d = I2X::SQLDetector.new(self)
rescue Exception => e
@response = {:status => 400, :error => e}
- p "[i2x] error: #{e}"
+ I2X::Config.log.error(self.class.name) {"#{e}"}
end
when 'csv'
begin
@d = I2X::CSVDetector.new(self)
rescue Exception => e
@response = {:status => 400, :error => e}
- p "[i2x] error: #{e}"
+ I2X::Config.log.error(self.class.name) {"#{e}"}
end
when 'xml'
begin
@d = I2X::XMLDetector.new(self)
rescue Exception => e
@response = {:status => 400, :error => e}
- p "[i2x] error: #{e}"
+ I2X::Config.log.error(self.class.name) {"#{e}"}
end
when 'json'
begin
@d = I2X::JSONDetector.new(self)
rescue Exception => e
@response = {:status => 400, :error => e}
- p "[i2x] error: #{e}"
+ I2X::Config.log.error(self.class.name) {"#{e}"}
end
end
# Start checkup
@@ -62,30 +63,30 @@
unless content.nil? then
@d.content = content
end
@checkup = @d.checkup
rescue Exception => e
- p "[i2x] error: #{e}"
+ I2X::Config.log.error(self.class.name) {"Checkup error: #{e}"}
end
# Start detection
begin
@d.objects.each do |object|
@d.detect object
end
@checkup[:templates] = @d.templates.uniq
rescue Exception => e
- p "[i2x] error: #{e}"
+ I2X::Config.log.error(self.class.name) {"Detection error: #{e}"}
end
begin
if @checkup[:status] == 100 then
process @checkup
end
rescue Exception => e
- p "[i2x] error: #{e}"
+ I2X::Config.log.error(self.class.name) {"Process error: #{e}"}
end
response = {:status => @checkup[:status], :message => "[i2x][Checkup][execute] All OK."}
end
@@ -94,23 +95,23 @@
# => Process agent checks.
#
def process checkup
begin
checkup[:templates].each do |template|
- p "[i2x][Agent] Processing #{template}"
+ I2X::Config.log.info(self.class.name) {"Delivering to #{template} template."}
checkup[:payload].each do |payload|
- puts "\t[i2x][Agent] Processing #{payload}"
+ I2X::Config.log.debug(self.class.name) {"Processing #{payload}."}
response = RestClient.post "#{I2X::Config.host}postman/deliver/#{template}.js", payload
case response.code
when 200
else
- puts "[i2x][Agent] unable to deliver \"#{payload}\" to \"#{template}\""
+ I2X::Config.log.warn(self.class.name) {"unable to deliver \"#{payload}\" to \"#{template}\""}
end
end
end
rescue Exception => e
- p "[i2x][Agent] error: #{e}"
+ I2X::Config.log.error(self.class.name) {"Processing error: #{e}"}
end
end
end
\ No newline at end of file