From 6b04e88815ed60f40c415efe3d6dd2c28aab70fd Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Fri, 6 Jul 2012 10:35:01 +0100 Subject: [PATCH] Added logging for all requests --- app/controllers/posts_controller.rb | 6 ++++++ app/models/error_log.rb | 8 ++++++++ test/fixtures/error_logs.yml | 9 +++++++++ test/unit/error_log_test.rb | 7 +++++++ 4 files changed, 30 insertions(+) create mode 100644 app/models/error_log.rb create mode 100644 test/fixtures/error_logs.yml create mode 100644 test/unit/error_log_test.rb diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 900db4c..c0c12fb 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -4,6 +4,12 @@ class PostsController < ApplicationController def near @posts = Post.near(params[:lat].to_f, params[:lon].to_f, params[:radius].to_f) + ErrorLog.create( + :ts => Time.now, + :params => params, + :pois_returned => @posts.size + ) + layar_response = { :layer => 'hyparlocal', :hotspots => @posts.collect { |p| post_to_poi(p) }, diff --git a/app/models/error_log.rb b/app/models/error_log.rb new file mode 100644 index 0000000..e2cd07d --- /dev/null +++ b/app/models/error_log.rb @@ -0,0 +1,8 @@ +class ErrorLog + include MongoMapper::Document + + key :ts, Time + key :params, Hash + key :pois_returned, Integer + +end diff --git a/test/fixtures/error_logs.yml b/test/fixtures/error_logs.yml new file mode 100644 index 0000000..ef76b86 --- /dev/null +++ b/test/fixtures/error_logs.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + ts: 2012-07-06 + params: + +two: + ts: 2012-07-06 + params: diff --git a/test/unit/error_log_test.rb b/test/unit/error_log_test.rb new file mode 100644 index 0000000..f0a068f --- /dev/null +++ b/test/unit/error_log_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ErrorLogTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end