Commit 464426aad1fcfc65a6888daa5e6ee090faa6bee8
Committed by
Rodrigo Souto
1 parent
80dec54f
Exists in
api_tasks
and in
4 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 | 3 | |
4 | 4 | module API |
5 | 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 | 11 | version 'v1' |
7 | 12 | prefix "api" |
8 | 13 | format :json | ... | ... |
lib/api/helpers.rb
... | ... | @@ -3,7 +3,7 @@ module API |
3 | 3 | PRIVATE_TOKEN_PARAM = :private_token |
4 | 4 | |
5 | 5 | def logger |
6 | - API.logger | |
6 | + @logger ||= Logger.new(File.join(Rails.root, 'log', "#{ENV['RAILS_ENV']}_api.log")) | |
7 | 7 | end |
8 | 8 | |
9 | 9 | def current_user |
... | ... | @@ -168,6 +168,17 @@ module API |
168 | 168 | end |
169 | 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 | 182 | def detect_stuff_by_domain |
172 | 183 | @domain = Domain.find_by_name(request.host) |
173 | 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