Commit 6386287afc177e736d5521d93a228ffe27b8745d
1 parent
d9c13a65
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Add logger to api requests
Showing
9 changed files
with
17 additions
and
11 deletions
Show diff stats
lib/api/api.rb
@@ -3,6 +3,11 @@ Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file} | @@ -3,6 +3,11 @@ Dir["#{Rails.root}/lib/api/*.rb"].each {|file| require file} | ||
3 | 3 | ||
4 | module API | 4 | module API |
5 | class API < Grape::API | 5 | class API < Grape::API |
6 | + before { start_log } | ||
7 | + before { setup_multitenancy } | ||
8 | + before { detect_stuff_by_domain } | ||
9 | + after { end_log } | ||
10 | + | ||
6 | version 'v1' | 11 | version 'v1' |
7 | prefix "api" | 12 | prefix "api" |
8 | format :json | 13 | format :json |
lib/api/helpers.rb
@@ -3,7 +3,7 @@ module API | @@ -3,7 +3,7 @@ module API | ||
3 | PRIVATE_TOKEN_PARAM = :private_token | 3 | PRIVATE_TOKEN_PARAM = :private_token |
4 | 4 | ||
5 | def logger | 5 | def logger |
6 | - API.logger | 6 | + @logger ||= Logger.new(File.join(Rails.root, 'log', "#{ENV['RAILS_ENV']}_api.log")) |
7 | end | 7 | end |
8 | 8 | ||
9 | def current_user | 9 | def current_user |
@@ -166,6 +166,17 @@ module API | @@ -166,6 +166,17 @@ module API | ||
166 | end | 166 | end |
167 | protected | 167 | protected |
168 | 168 | ||
169 | + def start_log | ||
170 | + logger.info "Started #{request.path}" | ||
171 | + end | ||
172 | + def end_log | ||
173 | + logger.info "Completed #{request.path}" | ||
174 | + end | ||
175 | + | ||
176 | + def setup_multitenancy | ||
177 | + Noosfero::MultiTenancy.setup!(request.host) | ||
178 | + end | ||
179 | + | ||
169 | def detect_stuff_by_domain | 180 | def detect_stuff_by_domain |
170 | @domain = Domain.find_by_name(request.host) | 181 | @domain = Domain.find_by_name(request.host) |
171 | if @domain.nil? | 182 | if @domain.nil? |
lib/api/v1/articles.rb
1 | module API | 1 | module API |
2 | module V1 | 2 | module V1 |
3 | class Articles < Grape::API | 3 | class Articles < Grape::API |
4 | - before { detect_stuff_by_domain } | ||
5 | before { authenticate! } | 4 | before { authenticate! } |
6 | 5 | ||
7 | resource :articles do | 6 | resource :articles do |
@@ -19,7 +18,6 @@ module API | @@ -19,7 +18,6 @@ module API | ||
19 | # :params => API::Entities::Article.documentation | 18 | # :params => API::Entities::Article.documentation |
20 | # } | 19 | # } |
21 | get do | 20 | get do |
22 | - | ||
23 | articles = select_filtered_collection_of(environment, 'articles', params) | 21 | articles = select_filtered_collection_of(environment, 'articles', params) |
24 | present articles, :with => Entities::Article | 22 | present articles, :with => Entities::Article |
25 | end | 23 | end |
lib/api/v1/categories.rb
lib/api/v1/comments.rb
lib/api/v1/communities.rb
lib/api/v1/enterprises.rb
lib/api/v1/people.rb