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 | 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 |
... | ... | @@ -166,6 +166,17 @@ module API |
166 | 166 | end |
167 | 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 | 180 | def detect_stuff_by_domain |
170 | 181 | @domain = Domain.find_by_name(request.host) |
171 | 182 | if @domain.nil? | ... | ... |
lib/api/v1/articles.rb
1 | 1 | module API |
2 | 2 | module V1 |
3 | 3 | class Articles < Grape::API |
4 | - before { detect_stuff_by_domain } | |
5 | 4 | before { authenticate! } |
6 | 5 | |
7 | 6 | resource :articles do |
... | ... | @@ -19,7 +18,6 @@ module API |
19 | 18 | # :params => API::Entities::Article.documentation |
20 | 19 | # } |
21 | 20 | get do |
22 | - | |
23 | 21 | articles = select_filtered_collection_of(environment, 'articles', params) |
24 | 22 | present articles, :with => Entities::Article |
25 | 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