Commit 0ab79e200f9df196200f15e3c696b20fd6d78f8a
Committed by
Leandro Santos
1 parent
2bccb24f
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
10 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 |
| @@ -168,6 +168,17 @@ module API | @@ -168,6 +168,17 @@ module API | ||
| 168 | end | 168 | end |
| 169 | protected | 169 | protected |
| 170 | 170 | ||
| 171 | + def start_log | ||
| 172 | + logger.info "Started #{request.path}" | ||
| 173 | + end | ||
| 174 | + def end_log | ||
| 175 | + logger.info "Completed #{request.path}" | ||
| 176 | + end | ||
| 177 | + | ||
| 178 | + def setup_multitenancy | ||
| 179 | + Noosfero::MultiTenancy.setup!(request.host) | ||
| 180 | + end | ||
| 181 | + | ||
| 171 | def detect_stuff_by_domain | 182 | def detect_stuff_by_domain |
| 172 | @domain = Domain.find_by_name(request.host) | 183 | @domain = Domain.find_by_name(request.host) |
| 173 | if @domain.nil? | 184 | if @domain.nil? |
lib/api/v1/articles.rb
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